eject command is used to eject removable media such as CDs, DVDs, and USB drives from a Linux system. When you insert a removable device into your computer, it will be automatically mounted and made available to the user. The
eject command is used to unmount and eject the device safely.
The syntax for the
eject command is as follows:
eject [options] [device]
device is the name of the device you want to eject. If no device is specified,
eject will attempt to eject the default device, which is usually the CD/DVD drive.
For example, to eject a CD/DVD in the CD/DVD drive, you would use the following command:
To eject a USB drive, you would use the following command:
You can also use the
-T option to close the tray after ejecting the device:
eject -T /dev/cdrom
The following options are available for the
||Use the default device (usually the CD/DVD drive)|
||Use the default device and display a message when it is safe to remove|
||Close the tray after ejecting the device|
||Verbose mode (display more information)|
If you receive an error message when trying to eject a device, it could be because the device is still in use. Make sure that all files and applications that are using the device are closed before attempting to eject it.
If the device still cannot be ejected, try using the
umount command to unmount the device first:
Then try ejecting the device again:
eject command can also be used to eject trays on certain types of devices, such as tape drives. However, this functionality is not available on all devices.