How to eject CD/DVD tray from command line in Linux

If you are new to the command line in Linux, you might have read/heard that the command line is one of the most powerful features of Linux. Yes, that's true. Nearly all things that you can do through GUI, can be done through the command line.

What more, you can even eject/close your system's CD/DVD tray through the command line. If that catches your fancy, and you would like to know more information on it, then read on, as in this article we will explain how you can do this.

Please note that all the commands and instructions mentioned in this tutorial have been tested on Ubuntu 16.04 LTS.

Eject CD/DVD tray from command line in Linux using Eject command

Yes, the 'eject' command lets you do this. Here's how the command's man page describes it:

"Eject allows removable media (typically a CD-ROM, floppy disk, tape, or JAZ or ZIP disk) to be ejected under software control. The command can also control some multi-disc CD-ROM changers, the auto-eject feature supported by some devices, and close the disc tray of some CD-ROM drives."

To perform the operation, simply run the following command:


In case this command doesn't work, you can try the following:

eject /dev/cdrom
eject /dev/cdrw
eject /dev/dvd
eject /dev/dvdrom
eject /dev/dvdrw

And if none of these work, the you'll have to look for the correct device in the list generated by the following command:

ls -l /dev | grep '\->'

To close the drive, use the following command:

eject -t

Please note that not all devices support the aforementioned close command. For more information on eject, head to its man page.

1 thought on “How to eject CD/DVD tray from command line in Linux”

Leave a Comment