UNIX / Linux eject Command Examples

What is eject ?
4 eject examples
Syntax and Options
Related Commands

What is eject ?

eject command is mainly used to eject the CD / DVD tray. You can also close the tray using certain options.

eject command can be used to eject floppy disk, tape, or JAZ or ZIP disk. eject command can also be used to control the eject options.

If the device is mounted while trying to eject, it will be unmounted first before ejecting.

4 eject Examples

Eject any available device

Normal eject tries to eject the following devices in this order until it successds: CD-ROM, floppy disk, tape, or JAZ or ZIP disk.

$ eject

Eject a device by its name

You can eject a device by specifying its name. Eject a CDROM:

$ eject /dev/cdrom

The same way, you can eject any device by specifying the device name.

Close the tray using eject Command

You can close the CDROM tray by using -t option. This option is very useful when the system is located in a remote place.

$ eject -t

Not all the devices support this functionality, when your device does not supports you will get the following error.

$ eject -t
eject: CD-ROM tray close command failed: Input/output error

Lock the hardware eject button

You can enable this option to disable the eject button. This avoids accidental ejecting of the device when you are carrying a laptop in a bag.

The device’s hardware eject button can be locked (disabled) as shown below.

$ eject -i on
CD-Drive may NOT be ejected with device button

Once you have the lock enabled you cannot eject the drive, you can disable it as,

$ eject -i off
CD-Drive may be ejected with device button

Syntax and Options

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

Short Option Option Description
-d invoked with this option, eject lists the default device name
-a on|1|off|0 This option controls the auto-eject mode, supported by some devices. When enabled,the drive automatically ejects when the device is closed
-c <slot> With this option a CD slot can be selected from an ATAPI/IDE CD-ROM changer. Linux2.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 this option the drive is given a CD-ROM tray close command. Not all devices sup-port this command
-T 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> this option the drive is given a CD-ROM select speed command. The speed argu- ment 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 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 this option the selected device is displayed but no action is performed
-r this option specifies that the drive should be ejected using a CDROM eject command
-s This option specifies that the drive should be ejected using SCSI commands
-f This option specifies that the drive should be ejected using a removable floppy diskeject command
-q This option specifies that the drive should be ejected using a tape drive offlinecommand
-p This option allow you to use /proc/mounts instead /etc/mtab. It also passes the -noption to umount(1)
-m This option allows eject to work with device drivers which automatically mount remov-able media and therefore must be always mount(1)ed. The option tells eject to not try to unmount the given device, even if it is mounted according to /etc/mtab or /proc/mounts


Related Commands

mount
umount

Comments on this entry are closed.

  • RAGHU SUBRAMANIAM June 3, 2010, 10:49 pm

    -i is not there in RHEL