Eject/Close CD or DVD media with shell command

cuckoo clockShell command eject that is available by default in most of Linux distributions, allows to open and sometimes close removable media tray (usually it’s CD-ROM or DVD media).

To eject media:

eject /dev/cdrom

or

eject cdrom

As you see the name of device can be a device file or mount point, either a full path or with the leading “/dev”, “/media” or “/mnt” omitted. If no name is specified, the default name “cdrom” is used. With -c option a CD slot can be selected from an ATAPI/IDE CD-ROM changer.

To close tray:

eject -t cdrom

Dear reader, I hope you know what use eject command for if you came here, but let me suggest one more application. You can use this command to make your own cuckoo clock! 🙂

Just put little shell script opening and closing cdrom or dvd tray into cron…

SHARE:
nv-author-image

Stefan Durand

My name is Stefan, I'm the admin of LinuxScrew. I am a full-time Linux/Unix sysadmin, a hobby Python programmer, and a part-time blogger. I post useful guides, tips, and tutorials on common Linux and Programming issues. Feel free to reach out in the comment section.

4 thoughts on “Eject/Close CD or DVD media with shell command”

  1. Thank you. My desktop now has a pair of application links – "Open_DVD" and "Close_DVD". These replace what I was doing with "myComputer.desktop".

  2. The `eject -t` is a viable option for systems with electronically controlled media drives. Unfortnately, Dell 1950 and 2950 systems have simple physical/mechanical interlocks that work to eject the drive with the `eject` command, and/or pushing the drive open button. `-t` doesn't work to close the drives on such systems.

    R,

    -Joe Wulf, RHCT, VCP, USN(RET)

    Senior IA Engineer/ISSE

    ProSync Technology Group

  3. Every few years, after a fresh install of an actual Distro, i come along and smile.

    Take the commands – put them to a hotkey/shortcut – forget them. XD
    Surely they can be found elsewhere…. But who cares???
    Right now its 13 years ago, that this was written!

    So, thanks for this!!!1

Leave a Reply

Your email address will not be published. Required fields are marked *