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 | mount_point>
PARAMETERS
-h, --help
Displays a help message and exits.
-v, --verbose
Enables verbose output, showing more details about the operation.
-d, --default
Ejects the default device if no device is specified on the command line.
-r, --cdrom
Treats the specified device as a CD-ROM device, using CD-ROM specific commands.
-t, --trayclose
Closes the CD/DVD tray on an optical drive.
-x <speed>, --speed <speed>
Sets the CD-ROM speed to the specified value. The speed is in X units (e.g., 2 for 2x speed).
-s, --scsi
Ejects a SCSI device, which can include Jaz, Zip, or other SCSI-connected removable drives.
-p, --floppy
Ejects a floppy disk from the specified floppy drive.
-a, --tape
Ejects a tape from a tape changer device.
-c <slot>, --changerslot <slot>
Selects a specific slot in a CD-ROM changer device for ejection or loading.
-i <slot>, --changerslot-info <slot>
Shows information about a specific slot in a CD-ROM changer.
-F, --force
Forces ejection even if the device is busy. Use with caution, as this can lead to data loss or corruption if the device is not properly unmounted first.
-N, --nodevnodes
Prevents eject from using /dev/disk/by-id paths, which can be useful in certain environments.
-T, --trayopen
Opens the CD/DVD tray. For many optical drives, this is the default action when no other option is specified.
-q, --quit
Exits immediately after attempting the operation, without waiting for the device status.
-V, --version
Displays version information for the eject command and exits.
<device | mount_point>
The target device to eject, specified either as a device file (e.g., /dev/sr0, /dev/sdb) or its mount point (e.g., /mnt/cdrom).
DESCRIPTION
The eject command in Linux is a utility used to control the ejection mechanism of various removable media devices. It provides a software interface to eject media such as CD-ROMs, DVDs, floppy disks, tape cartridges, and even some SCSI devices like Jaz or Zip drives. When invoked on a mounted device, eject intelligently attempts to unmount the filesystem before physically ejecting the media, ensuring data integrity and preventing potential corruption. This makes it a safer alternative to simply pulling out media from a drive.
Beyond basic ejection, eject offers functionalities like closing the drive tray (for optical drives), setting CD-ROM read speeds, and managing multi-disc CD changers by selecting specific slots. It is a crucial tool for systems interacting with physical media, allowing for graceful removal. While optical drives are less common in modern computers, eject remains relevant for unmounting and "ejecting" external USB drives or other removable storage devices in a controlled manner, even if a physical ejection mechanism isn't present in the same way as an optical drive. The command typically requires root privileges to operate, or it can be executed using sudo.
CAVEATS
The eject command typically requires root privileges or sudo to operate on device files. Not all hardware devices support all options (e.g., some older drives may not support tray close or speed setting). Using the --force option is risky and should be avoided unless absolutely necessary, as it bypasses safety checks and can lead to data loss or filesystem corruption if the device is still in use.
PERMISSIONS
To execute eject on most system devices, you typically need root privileges. This is because direct manipulation of hardware requires elevated permissions to prevent unauthorized access or system instability. Users can usually achieve this by prefixing the command with sudo (e.g., sudo eject /dev/sr0).
AUTOMATIC UNMOUNTING
One of eject's key safety features is its attempt to automatically unmount the filesystem from the device before initiating the physical ejection. This prevents data corruption that could occur if the media is removed while the operating system is still performing read/write operations or if the filesystem is not cleanly unmounted.
HISTORY
The eject command has been a fundamental utility in Unix-like operating systems for decades, providing software control over removable media drives. Its development is closely tied to the evolution of physical media, from floppy disks to CD-ROMs, DVDs, and various SCSI-based removable storage solutions. Historically, it was crucial for systems to gracefully handle physical media interaction. Although optical drives are less prevalent in modern computing, eject remains part of the widely used util-linux package on many Linux distributions, maintaining its relevance for general device unmounting and safe removal procedures for any block device that supports a 'power off' or 'eject' command through the kernel's device drivers.