Ubuntu - Open/Close the CD-rom tray in command line

December 2016

In systems using Ubuntu , the free / open source operating system that uses the Linux kernel has many features that are meant to be convenient for its users. It has many functions just like Microsoft's Windows OS , for instance, the user can open or close the CD tray. No software is required to complete this process. The CD tray can be opened or closed in Ubuntu with the help of the command line. Two separate commands have to be used for opening and closing the tray. Alternatively a .sh file can be created to complete the process.


Like Windows, it is also possible to open and close the CD via command line in Ubuntu, but this time without software. You simply need one command to open it, and another to close it again. Below are the commands you will need:


The command to open the drive:
 > eject

The command to close the drive:

Alternative solution

It is also possible to open and close it indefinitely by creating a .sh file with the following code:

while [ 1 = 1 ]      
 #eject drive      
 #close it      
 eject -t      
  • Then to run the file: > bash/path/to/file.sh

Related :

This document entitled « Ubuntu - Open/Close the CD-rom tray in command line » from CCM (ccm.net) is made available under the Creative Commons license. You can copy, modify copies of this page, under the conditions stipulated by the license, as this note appears clearly.