Skip to content

eject command in Linux

The eject command in Linux is used to safely remove external storage devices such as USB drives, CDs, or DVDs from your system. It ensures that all data is written to the device before it is unmounted and ejected, preventing potential data loss or corruption. This command is especially useful for ensuring that your removable storage devices are safely disconnected from your system without any risk of damage.

Terminal window
eject [options] [device]
OptionDescription
-d, —defaultUse the default ejection method
-r, —retractEject the media and retract the device
-T, —traycloseClose the tray if the drive supports this
-v, —verboseDisplay more information during ejection
-n, —noopDo not actually eject, just show what would happen
ParameterDescription
deviceThe device node or mount point to eject
Terminal window
eject

Ejects the CD/DVD tray in the optical drive.

Terminal window
eject /dev/cdrom

Ejects the CD/DVD tray by specifying the device name “/dev/cdrom”.

Terminal window
eject /mnt/cdrom

Ejects the CD/DVD tray by specifying the mount point “/mnt/cdrom”.

Terminal window
eject /dev/cdrom /dev/cdrom1

Ejects multiple CD/DVD trays at the same time by specifying multiple device names.

Terminal window
eject /media/cdrom

Ejects the CD/DVD tray for the media mounted at “/media/cdrom”.

Terminal window
eject -r

Ejects the CD/DVD tray without automatically closing it after ejection.

Display help information for the eject command

Section titled “Display help information for the eject command”
Terminal window
eject --help

Shows the help manual for the eject command with detailed information on its usage.

Terminal window
ssh user@remote_host eject /dev/cdrom

Ejects the CD/DVD tray of a remote device by running the eject command over SSH connection.

To use the eject command in Linux, execute the following command:

Terminal window
eject /dev/sdb

What is the purpose of the eject command in Linux?

Section titled “What is the purpose of the eject command in Linux?”

The eject command in Linux is used to eject removable media, such as CDs, DVDs, or USB drives, from the system.

How do I force eject a stuck CD/DVD using eject in bash?

Section titled “How do I force eject a stuck CD/DVD using eject in bash?”

To force eject a stuck CD/DVD using the eject command in Linux, you can use the following command:

Terminal window
eject -f /dev/sr0

How can I display help information for the eject command in Linux?

Section titled “How can I display help information for the eject command in Linux?”

To display help information for the eject command in Linux, you can use the following command:

Terminal window
eject --help

How do I eject a specific drive with eject in bash?

Section titled “How do I eject a specific drive with eject in bash?”

To eject a specific drive using the eject command in Linux, you can specify the device as an argument. For example:

Terminal window
eject /dev/sdc

How do I prevent the tray from closing after ejecting with the eject command in Linux?

Section titled “How do I prevent the tray from closing after ejecting with the eject command in Linux?”

To prevent the tray from closing automatically after ejecting using the eject command in Linux, you can use the following command:

Terminal window
eject -T /dev/sr0

How do I list available devices for eject in Linux?

Section titled “How do I list available devices for eject in Linux?”

To list available devices for the eject command in Linux, you can use the following command:

Terminal window
eject -d

Can I use the eject command to eject network shares in Linux?

Section titled “Can I use the eject command to eject network shares in Linux?”

No, the eject command in Linux is specifically designed for ejecting physical removable media and cannot be used to eject network shares.

How do I eject multiple devices simultaneously with the eject command in bash?

Section titled “How do I eject multiple devices simultaneously with the eject command in bash?”

To eject multiple devices simultaneously using the eject command in Linux, you can specify each device as separate arguments. For example:

Terminal window
eject /dev/sdb /dev/sdc
  • Ejecting removable media such as CDs or DVDs
  • Ejecting external storage devices like USB drives
  • Ejecting virtual disks mounted on the system