eject

system managementLinux
The eject command is one of the most frequently used commands in Linux/Unix-like operating systems. eject Eject removable media such as CD/DVD discs or USB drives

Quick Reference

Command Name:

eject

Category:

system management

Platform:

Linux

Basic Usage:

eject [options] [arguments]

Common Use Cases

  • 1

    Media removal

    Safely eject CD/DVD discs from optical drives

  • 2

    USB device unmounting

    Safely remove USB storage devices to prevent data loss

  • 3

    Tray control

    Open or close CD/DVD drive trays programmatically

  • 4

    Device management

    Manage removable media in headless or server environments

Syntax

eject [options] [device]

Options

Option Description
-d Display default device name
-a on|off|1|0 Enable/disable auto-eject mode
-c slot Select CD-ROM slot to use
-h Display help information
-n Don't eject, just show device name
-p Full device name with the /dev/ prefix
-r Eject media and close the tray
-t Close the tray
-T Toggle tray state (open/close)
-v Enable verbose output
-x Eject media from an XA-capable CD-ROM drive

Examples

How to Use These Examples

The examples below show common ways to use the eject command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.

# Basic Examples Basic
eject
Eject the default CD/DVD drive.
eject /dev/cdrom
Eject the CD/DVD drive at /dev/cdrom.
# Advanced Examples Advanced
eject -t Close the CD/DVD tray instead of opening it. eject -T Toggle between ejecting and closing the CD/DVD tray. eject -r Eject the medium and then immediately close the tray. eject -v /dev/sdc Eject with verbose output showing what's happening.

Try It Yourself

Practice makes perfect! The best way to learn is by trying these examples on your own system with real files.

Understanding Syntax

Pay attention to the syntax coloring: commands, options, and file paths are highlighted differently.

Notes

The eject command is used to eject removable media such as CD-ROMs, DVDs, floppy disks, tape drives, and some USB storage devices. It works by sending the appropriate SCSI, IDE, or USB commands to the device. When called without any arguments, eject will use the default device (usually /dev/cdrom or a symbolic link to the actual device). To eject a specific device, you can specify either the mount point (like /mnt/cdrom) or the device name (like /dev/cdrom). In addition to opening CD/DVD trays, eject can also logically unmount media that doesn't have a physical eject mechanism, such as USB flash drives, ensuring that all data is properly written before removal. Note that modern desktop environments often handle media ejection automatically through their file managers, but the eject command remains useful for scripting and server environments without a GUI.

Tips & Tricks

1

Use the -t option to close the tray instead of opening it

2

Use the -T option to toggle the tray state (open/close)

3

You can specify either a device name (/dev/cdrom) or a mount point (/mnt/cdrom)

4

Use the -v option for verbose output to see what's happening

5

Use the -r option to eject and then immediately close the tray

Common Use Cases

Media removal

Safely eject CD/DVD discs from optical drives

USB device unmounting

Safely remove USB storage devices to prevent data loss

Tray control

Open or close CD/DVD drive trays programmatically

Device management

Manage removable media in headless or server environments

Automating media handling

Script media insertion and removal in automated systems

Related Commands

These commands are frequently used alongside eject or serve similar purposes:

Use Cases

1

Media removal

Safely eject CD/DVD discs from optical drives

2

USB device unmounting

Safely remove USB storage devices to prevent data loss

3

Tray control

Open or close CD/DVD drive trays programmatically

4

Device management

Manage removable media in headless or server environments

5

Automating media handling

Script media insertion and removal in automated systems

Learn By Doing

The best way to learn Linux commands is by practicing. Try out these examples in your terminal to build muscle memory and understand how the eject command works in different scenarios.

$ eject
View All Commands