How to Eject a CD From the Command Line

For those with nothing better to do at the command line, the eject command lets you open and close the tray in your CD drive.


Enter eject to eject the tray, and eject -t to close the try.

You may be surprised to see the wealth of options eject supports given its purpose, so enter man eject to read what is possible.

Let’s automate the process. Write a looping script, and watch the tray receive a workout!

#!/bin/bash
function ejectme()
{
   # Eject
   echo "Now you see me!"
   eject
   # Close
   echo "Now you don't"
   eject -t
}

for ((i = 0; i < 5; i++))
do
   ejectme
done

And for those feeling particularly mischievous, SSH into another computer and what watch happens after entering eject. Gives “remote administration” a whole new meaning!

About these ads

, ,

  1. #1 by anthonyvenable110 on May 19, 2012 - 7:55 PM

    Ok that was a great idea!!!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 34 other followers

%d bloggers like this: