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

February 2017

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.

Introduction


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:

Solution


The command to open the drive:
 > eject

The command to close the drive:
 >eject-t

Alternative solution


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

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

Related


Published by jak58. Latest update on February 19, 2012 at 02:16 PM by Paul Berentzen.
This document, titled "Ubuntu - Open/Close the CD-rom tray in command line," is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (ccm.net).