eject
Eject removable media
TLDR
Display the default device
Eject the default device
Eject a specific device (the default order is cd-rom, scsi, floppy, and tape)
Toggle whether a device's tray is open or closed
Eject a cd drive
Eject a floppy drive
Eject a tape drive
Set whether the physical eject button is [i]gnored (on prevents ejecting)
SYNOPSIS
eject [options] [device]
PARAMETERS
-h, --help
Display help and exit
-V, --version
Output version information and exit
-v, --verbose
Enable verbose output with device and ioctl details
-t, --close
Close the CD/DVD tray
-T, --eject-open
Open tray, then close it (toggle)
-x N, --cdspeed N
Set CD speed to N (0=no change, 1-65535)
-i ID, --cdid ID
Set CD-ROM ID (0-65535, MMC drives only)
-p, --proc
Adjust /proc/partitions entry
-s, --smart
Use smartctl(8) data (if compiled with support)
-r, --raw
Use raw device name, ignore symlinks
DESCRIPTION
The eject command is a versatile utility for managing removable media devices like CD/DVD drives, floppy disks, tapes, and some USB storage. It interfaces directly with kernel drivers via ioctl calls to physically eject media, close/open trays, adjust speeds, or change modes.
Without a device argument, it targets the default CD-ROM device (often /dev/cdrom, symlinked to /dev/sr0). Specify a device like /dev/sr0 or /dev/fd0 for others. Common uses include scripting backups, automating media swaps, or CLI control when no GUI is available.
Key features: tray control (-t to close, -T to toggle), speed setting (-x for CD playback rates), verbose logging (-v), and auto-detection. It supports SCSI, ATAPI, and other interfaces but relies on proper driver support.
On modern systems, it's often complemented by udisks2 or polkit-enabled tools for unmounting. Success requires unmounted filesystems and user privileges (typically cdrom group membership). Widely portable across Linux distros via the eject package.
CAVEATS
Fails if media/filesystem mounted (unmount first); limited drive support for advanced options; requires cdrom group or root; no USB auto-unmount.
DEFAULT BEHAVIOR
Targets /dev/cdrom; auto-detects if absent.
EXAMPLES
eject (default CD)
eject -t /dev/sr0 (close tray)
eject -v /dev/fd0 (verbose floppy)
HISTORY
Written by Jeff Tranter in 1994; evolved from early Linux CD-ROM tools; maintained in eject package (util-linux optional); key for pre-GNOME/KDE media handling.


