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…

 
 
» You might also be interested in the following articles:
Quick shell change for user in Unix or Linux
Can’t find usable shell script encryption solution…
Automatic "zombie" processes killing (shell script)
Comparing Bash with… Windows command line shell…
iPhone as network-enabled root shell



» Want to stay up to date? Subscribe to our E-MAIL or RSS feed!

3 Responses to “Eject/Close CD or DVD media with shell command”


  1. 1 ramin

    I want to eject CD Rom and the enter a CD into Cd rom .
    but Linux( Fedora 11 ) not allow . please help me

  2. 2 Ted King

    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”.

  3. 3 Joe Wulf

    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

Leave a Reply




Friendly Sites:Who is behind Linux Screw?
Aspiring Sysadmin | GeekyBits³ | Bash Cures Cancer | TOTMS
Linux Operating System | Small Linux Deployments | My SysAd Blog
The Danesh Project | ZEPY | Linux config Wiki | Planet Sysadmin
The Sys Admin | {buhay sysad} | a non-geek's linux notes
Linux HOWTOs, Tutorials & Projects with Adam Palmer | LinuxAlt.Com
My name is Artem N. (artiomix AT gmail DOT com) and I'm Linux/Unix, Cisco systems engineer. The main idea of Linux Screw is to share relevant knowledge, skills and observations over The Web. Here you can find a lot of information related to different Linux distributions, FreeBSD, IOS as well as a other Open Source around staff. Read more ››