eject – Used to Eject the Extractable Device

The 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.

Overview

The syntax for the eject command is as follows:

eject [options] [device]

Where 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:

eject /dev/cdrom

To eject a USB drive, you would use the following command:

eject /dev/sdb1

You can also use the -T option to close the tray after ejecting the device:

eject -T /dev/cdrom

Options

The following options are available for the eject command:

Option Description
-d Use the default device (usually the CD/DVD drive)
-s Use the default device and display a message when it is safe to remove
-T Close the tray after ejecting the device
-v Verbose mode (display more information)
-h Display help

Troubleshooting Tips

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:

umount /dev/cdrom

Then try ejecting the device again:

eject /dev/cdrom

Notes

The 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.