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

Ask a question
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

Ubuntu - Shell script to execute/run
Ubuntu - Unable to run applications