How to Use eject Command in Linux – Examples
The basic syntax of the eject command is:
The eject command requires the root privileges to run, and execute the commands with sudo or as a root user.
Examples of the eject command:
Example i: To eject the default removable device
Example ii: To eject the CD-ROM
The above command will eject the CD-ROM from your system and replace the path /cd/rom with the actual path of the CD-ROM.
The following command will close the tray of the CD-ROM if it’s open:
Example iii: To eject the hard disk drive
Or:
To list the default device name via the eject command use the parameter -d with it:
If you want to control the auto-eject mode which is supported by some devices use the following command:
If you want to display the selected devices without performing any action; use the below command:
To display the help of the eject command use the following command:
Conclusion
The eject command in Linux is used to eject the removable media such as CD-ROM, DVD, floppy, USB storage device. When you insert the media into the device, the system makes it mounted and you must remove it after use. The eject command unmounts the device and removes it without affecting your data. It is also used to close the tray of CD-ROM if it is open.