Linux Mint

How to Use eject Command in Linux – Examples

eject command in Linux is used to eject removable media such as floppy, CD, and DVD. You have to enter the name of the device while executing the command, if no device name is named then CD-ROM will be ejected by default. The eject command is also used to close the tray if it’s open. In this tutorial, we will explain the eject command with examples.

How to Use eject Command in Linux – Examples

The basic syntax of the eject command is:

eject [options] [device]

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

eject

Example ii: To eject the CD-ROM

eject cdrom

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:

eject -t /dev/cdrom

Example iii: To eject the hard disk drive

eject <hdd> or eject <sda>

Or:

eject <sda>

To list the default device name via the eject command use the parameter -d with it:

eject -d

If you want to control the auto-eject mode which is supported by some devices use the following command:

eject -a on

If you want to display the selected devices without performing any action; use the below command:

eject -n

To display the help of the eject command use the following command:

eject -h

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.

About the author

Zainab Rehman

I'm an author by profession. My interest in the internet world motivates me to write for Linux Hint and I'm here to share my knowledge with others.