Open In App

eject command in Linux with examples

Last Updated : 15 May, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

eject allows ejecting a removable media (typically a CD-ROM, floppy disk, tape, or JAZ or ZIP disk) using the software. You can also control some multi-disc CD-ROM changers, the auto-eject feature (supported by some devices) and also close the disc tray of some CD-ROM drives. The methods of ejecting depend on the device type, whether it is a CD-ROM, SCSI device, removable floppy, or tape. The default action of eject is that it tries all four methods in order until it achieves success. The device is unmounted, if it is mounted, before ejecting.

Syntax:

eject [...OPTIONS]

Options of the eject command:

  • -h or –help : Display help for available commands.

    Syntax:

    eject -h

    Output:

  • -v or –verbose : Log out more information about the command’s execution.

    Syntax:

    eject -v

    Output:

  • -d or –default : List default device name.

    Syntax:

    eject -d

    Output:

  • -a on|1|off|0 or –auto on|1|off|0 : Control auto-eject mode supported by some devices with this command. Enable this to auto-eject when the device is closed.

    Syntax:

    eject -a on
  • -c or –changerslot : Select a CD slot from an ATAPI/IDE CD-ROM changer. You need Linux 2.0+ to use this feature. You have to make sure that the CD slot is not already in use. The first available slot is referred to as 0.

    Syntax:

    eject -c 0
  • -t or –trayclose : Use this command to give the drive a tray close command.

    Note: Hardware support for this feature is limited.

    Syntax:

    eject -t
  • -T or –traytoggle : This option gives the tray close command, if the slot is open, or an eject command, if the slot is closed.

    Note: Hardware support for this command is limited, as it makes use of the above -t command.

    Syntax:

    eject -T
  • -x or –cdspeed : Give a CD-ROM select speed command to the drive with this option. An argument is a number, which indicates the desired speed (e.g. 3 for 3X speed), or 0 for maximum data rate. Device support for this command is limited, and you can only specify speeds that the drive is capable of. The option is cleared everytime the media is changed. This option can also be used with -c or -t command.

    Syntax:

    eject -x 0
  • -X or –listspeed : Display a list of available speeds from the CD-ROM drive using this option. You can use the speeds listed as an argument in the -x option. You need Linux 2.6.13+ to work with this option. On older versions, it will only report the maximum speed. Also, some drives may not correctly report the speed, thus this option does not work with them.

    Syntax:

    eject -X
  • -n or –noop : Display the selected device, but perform no action using this option.

    Syntax:

    eject -n

    Output:

  • -r or –cdrom : Specify that the drive should be ejected using a CDROM eject command using this option.

    Syntax:

    eject -r
  • -s or –scsi : Specify that the drive should be ejected using SCSI commands using this option.

    Syntax:

    eject -s
  • -f or –floppy : Specify that the drive should be ejected using a removable floppy disk eject command using this option.

    Syntax:

    eject -f
  • -q or –tape : Specify that the drive should be ejected using a tape drive offline command using this option.

    Syntax:

    eject -q
  • -p or –proc : Use /proc/mounts instead /etc/mtab with this command. It also passes the -n option to umount.
    Syntax:

    eject -p
  • -m or –no-unmount : Allow eject to work with device drivers which autonomously mount removable media and therefore must be always mounted. The option tells eject not to try to unmount the given device, even if it is mounted according to /proc/mounts or /etc/mtab.

    Syntax:

    eject -m
  • -V or –version : Log the version number to console and exit.

    Syntax:

    eject -V

    Output:

Exit Status: On successful operation, 0 is returned, and on failed operation, 1 is returned.


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads