Linux eject command

Updated: 06/22/2024 by Computer Hope
eject command

On Unix-like operating systems, the eject command allows removable media (typically an optical disc) to be ejected under software control. The command can also control some multi-disc CD-ROM (Compact Disc Read-Only Memory) changers, the auto-eject feature supported by some devices, and close the disc tray of some CD-ROM drives.

This page describes the GNU/Linux version of eject.

Description

When the eject command is executed, the device corresponding to <name> is ejected. The name is 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 (Small Computer System Interface) 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.

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 (Compact Disc) slot can be selected from an ATAPI (AT Attachment Packet Interface)/IDE (Integrated Drive Electronics) CD-ROM changer. Linux 2.0 or higher is required to use this feature. The CD-ROM drive cannot 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 called 0, not 1.
-i on|1|off|0 This option controls locking of the hardware eject button. When enabled, the drive does not eject 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 the drive can perform. 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 is probed to detect the available speeds. The output lists 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, only the maximum speed is reported. Also, note that some drives may not correctly report the speed; 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 CD-ROM 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 lets you 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's mounted according to /etc/mtab or /proc/mounts.
-V, --version This option causes eject to display the program version and exit.

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.