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

If you are new to the command line of Linux, you may have read/heard that the command line is one of the most powerful features of Linux. Yes, this is true. Almost all the things you can do through the GUI, you can also do through the command line.

Even more, you can even eject/close your system's CD/DVD drive from the command line. If this has piqued your interest and you want to know more about it, then read on as this article explains how you can do this.

Please note that all commands and instructions mentioned in this guide have been tested on Ubuntu 22.04 LTS. But the same commands will work on any other modern Linux distribution too.

Eject CD/DVD drive from the command line in Linux with "eject" command

Yes, you can do this with the "eject" command. The command's man page describes it as follows:

"Eject allows you to eject removable media (typically a CD-ROM, a floppy disk, a tape, or a JAZ or ZIP disk) under software control. The command can also control some multi-disc CD-ROM changers, the auto-eject feature supported by some devices, and the closing of 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, 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.

Leave a Comment