Linux eject command

Updated: 06/16/2017 by Computer Hope

About eject

eject allows removable media (typically an optical disc) to be ejected under software control. The command can also control some multi-disc CD-ROM changers, the auto-eject feature supported by some devices, and close the disc tray of some CD-ROM drives.

The device corresponding to <name> is ejected. The name can be a device file or mount point, either a full path or with the leading "/dev", "/media" or "/mnt" omitted. If no name is specified, the default name "cdrom" is used.

There are four different methods of ejecting, depending on whether the device is a CD-ROM, SCSI device, removable floppy, or tape. By default eject tries all four methods in order until it succeeds.

If the device is currently mounted, it is unmounted before ejecting.

eject syntax

eject -h
eject [-vnrsfmqp] [<name>]
eject [-vn] -d
eject [-vn] -a on|off|1|0 [<name>]
eject [-vn] -c slot [<name>]
eject [-vn] -i on|off|1|0 [<name>]
eject [-vn] -t [<name>]
eject [-vn] -T [<name>]
eject [-vn] -x <speed> [<name>]
eject [-vn] -X [<name>]
eject -V

Options

-h, --help

This option causes eject to display a brief description of the command options.

-v, --verbose

This makes eject run in verbose mode; more information is displayed about what the command is doing.

-d, --default

If invoked with this option, eject lists the default device name.

-a on|1|off|0, --auto

This option controls the auto-eject mode, supported by some devices. When enabled, the drive automatically ejects when the device is closed.

-c <slot>, --changerslot

With this option a CD slot can be selected from an ATAPI/IDE CD-ROM changer. Linux 2.0 or higher is required to use this feature. The CD-ROM drive can not be in use (mounted data CD or playing a music CD) for a change request to work. Please also note that the first slot of the changer is referred to as 0, not 1.

-i on|1|off|0

This option controls locking of the hardware eject button. When enabled, the drive will not be ejected when the button is pressed. This is useful when you are carrying a laptop in a bag or case and don't want it to eject if the button is inadvertently pressed.

-t, --trayclose

With this option the drive is given a CD-ROM tray close command. Not all devices support this command.

-T, --traytoggle

With this option the drive is given a CD-ROM tray close command if it's opened, and a CD-ROM tray eject command if it's closed. Not all devices support this command, because it uses the above CD-ROM tray close command.

-x <speed>, --cdspeed

With this option the drive is given a CD-ROM select speed command. The speed argument is a number indicating the desired speed (e.g. 8 for 8X speed), or 0 for maximum data rate. Not all devices support this command and you can only specify speeds that the drive is capable of. Every time the media is changed this option is cleared. This option can be used alone, or with the -t and -c options.

-X, --listspeed

With this option the CD-ROM drive will be probed to detect the available speeds. The output is a list of speeds which can be used as an argument of the -x option. This only works with Linux 2.6.13 or higher, on previous versions solely the maximum speed will be reported. Also note that some drive may not correctly report the speed and therefore this option does not work with them.

-n, --noop

With this option the selected device is displayed but no action is performed.

-r, --cdrom

This option specifies that the drive should be ejected using a CDROM eject command.

-s, --cdrom

This option specifies that the drive should be ejected using SCSI commands.

-f, --floppy

This option specifies that the drive should be ejected using a removable floppy disk eject command.

-q, --tape

This option specifies that the drive should be ejected using a tape drive offline command.

-p, --proc

This option allow you to use /proc/mounts instead /etc/mtab. It also passes the -n option to umount.

-m, --no-unmount

This option allows eject to work with device drivers which automatically mount removable media and therefore must be always mounted. The option tells eject to not try to unmount the given device, even if it is mounted according to /etc/mtab or /proc/mounts.

-V, --version

This option causes eject to display the program version and exit.

eject examples

eject

Eject the default device.

eject cdrom

Eject a device or mount point named cdrom.

eject /dev/cdrom

Same as above, but using the device name.

eject /mnt/cdrom/

Same as above, using the mount point.

eject hdd

Eject 4th IDE device.

eject sda

Eject first SCSI device.

eject sda4

Eject using SCSI partition name.

eject -v -c4 /dev/cdrom

Eject 5th disc on multi-disc changer.

mount — Mount a file system so that its data may be accessed.
umount — Unmount a file system, making its data inaccessible.