Eject a disc or USB drive with the eject command

Safely open the DVD tray or mark a USB stick safe to remove without using a file manager.

LinuxdiskusbMedium risk
Run eject /dev/sr0 to open the optical drive tray, or eject /media/user/USB to unmount and release a USB drive.

01Command

Command
$ eject /dev/sr0 && eject /media/$USER/USBDRIVE

02What it does

eject first unmounts any filesystem on the device, then either opens the tray of an optical drive or signals the kernel that removable media can be pulled out. You can pass the device node (/dev/sr0) or an existing mount point. If the drive is busy, close programs using it and retry.

03Risk

RiskMedium risk
!Warning: Ejecting unmounts the volume — any file copy still running will fail. Wait until transfers finish, then eject. Never yank a drive while its LED is blinking.

04Undo

✓No undo needed — this command does not change persistent state.

05Sources

  • eject(1) — eject removable media
    manpages.ubuntu.com · community · 2026-09-17
    Evidence: eject unmounts the filesystem if mounted and opens the tray or marks the device safe to remove; it accepts device names like /dev/sr0 or mount points.

Last verified: 2026-09-18 · Category: Files & Folders

06Related solutions