eject command in Linux with examples
Last Updated :
25 Sep, 2024
eject allows ejecting a removable media (typically a CD-ROM, floppy disk, tape, or JAZ or ZIP disk) using the software. You 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.
Syntax
eject [...OPTIONS]
The utility is especially useful for managing different device types, including CD-ROMs, SCSI devices, removable floppy disks, and tape drives. The eject command tries multiple methods to successfully eject the media depending on the device type. If the device is mounted, it will automatically unmount it before ejecting.
Common Options of the eject Command
1. -h or –help:
Display help for available commands.
Syntax:
eject -h
Output:

This command provides an overview of all available options and usage examples.
2. -v or –verbose:
Logs more detailed information about the command’s execution.
Syntax:
eject -v
Output:

3. -d or –default:
List default device name.
Syntax:
eject -d
Output:

4. -a on|1|off|0 or –auto on|1|off|0:
Control auto-eject mode supported by some devices with this command. Enable this to auto-eject when the device is closed.
Syntax:
eject -a on
5. -c or –changerslot:
Select a CD slot from an ATAPI/IDE CD-ROM changer. You need Linux 2.0+ to use this feature. You have to make sure that the CD slot is not already in use. The first available slot is referred to as 0.
Syntax:
eject -c 0
6. -t or –trayclose:
Use this command to give the drive a tray close command.
Note: Hardware support for this feature is limited.
Syntax:
eject -t
7. -T or –traytoggle:
This option gives the tray close command, if the slot is open, or an eject command, if the slot is closed. 0
Note: Hardware support for this command is limited, as it makes use of the above -t command.
Syntax:
eject -T
8. -x or –cdspeed:
Give a CD-ROM select speed command to the drive with this option. An argument is a number, which indicates the desired speed (e.g. 3 for 3X speed), or 0 for maximum data rate. Device support for this command is limited, and you can only specify speeds that the drive is capable of. The option is cleared everytime the media is changed. This option can also be used with -c or -t command.
Syntax:
eject -x 0
9. -X or –listspeed:
Display a list of available speeds from the CD-ROM drive using this option. You can use the speeds listed as an argument in the -x option. You need Linux 2.6.13+ to work with this option. On older versions, it will only report the maximum speed. Also, some drives may not correctly report the speed, thus this option does not work with them.
Syntax:
eject -X
10. -n or –noop:
Display the selected device, but perform no action using this option.
Syntax:
eject -n
Output:

11. -r or –cdrom:
Specify that the drive should be ejected using a CDROM eject command using this option.
Syntax:
eject -r
12. -s or –scsi:
Specify that the drive should be ejected using SCSI commands using this option.
Syntax:
eject -s
13. -f or –floppy:
Specify that the drive should be ejected using a removable floppy disk eject command using this option.
Syntax:
eject -f
14. -q or –tape:
Specify that the drive should be ejected using a tape drive offline command using this option.
Syntax:
eject -q
15. -p or –proc:
Use /proc/mounts instead /etc/mtab with this command. It also passes the -n option to umount.
Syntax:
eject -p
16. -m or –no-unmount:
Allow eject to work with device drivers which autonomously mount removable media and therefore must be always mounted. The option tells eject not to try to unmount the given device, even if it is mounted according to /proc/mounts or /etc/mtab.
Syntax:
eject -m
17. -V or –version:
Log the version number to console and exit.
Syntax:
eject -V
Output:

Exit Status
- 0: The operation was successful.
- 1: The operation failed.
Conclusion
The eject command in Linux provides a simple yet powerful way to manage removable media such as CD-ROMs, floppy disks, and tape drives. By using its various options, you can control eject behavior, toggle the tray, set CD-ROM speeds, and more.
eject command in Linux – FAQs
What is the eject command in Linux?
The eject command in Linux is a utility that allows users to eject removable media like CD-ROMs, floppy disks, tapes, or even ZIP and JAZ disks.
How do I use the eject command to eject a CD-ROM?
To eject a CD-ROM, you simply need to run the following command:
eject /dev/cdrom
Can the eject command close the CD-ROM tray?
Yes, if your CD-ROM drive supports it, you can use the -t option to close the tray:
eject -t /dev/cdrom
How do I enable auto-eject mode using the eject command?
Auto-eject mode can be enabled for some supported devices. To turn on auto-eject, use:
eject -a on /dev/cdrom
Master DevOps and also get 90% Course fee refund on completing 90% course in 90 days! Take the Three 90 Challenge today.
The most sought-after Three 90 challenge has started and this is your chance to upskill and get 90% refund. What more motivation do you need? Start the challenge right away!
Similar Reads
dmidecode command in Linux with Examples
The 'dmidecode' command, short for Desktop Management Interface table decoder, is a powerful utility in Linux that retrieves detailed information about your system's hardware components. This tool reads the DMI table and presents the data in a human-readable format, making it invaluable for system a
4 min read
domainname Command in Linux With Examples
domainname command in Linux is used to return the Network Information System (NIS) domain name of the host. You can use hostname -d command as well to get the host domainname. If the domain name is not set up in your host then the response will be "none". In networking terminology, the domain name i
3 min read
dos2unix and unix2dos commands
Sometimes, you will need to move files between windows and unix systems. Window files use the same format as Dos, where the end of line is signified by two characters, Carriage Return or CR or \r followed by Line Feed or LF or \n. Unix files, on the other hand, use only Line Feed (\n). unix2dos is a
4 min read
dosfsck command in Linux with Examples
dosfsck stands for DOS File System Consistency Check and is part of the dosfstools package in Unix-like operating systems. This command diagnoses and repairs MS-DOS filesystems (FAT12, FAT16, FAT32). Before running dosfsck, it is crucial to unmount the filesystem to avoid data corruption. Syntax:dos
4 min read
dstat Command in Linux With Examples
dstat is a tool that is used to retrieve information or statistics form components of the system such as network connections, IO devices, or CPU, etc. It is generally used by system administrators to retrieve a handful of information about the above-mentioned components of the system. It itself perf
3 min read
du Command in LINUX
The du command in Linux is a powerful utility that allows users to analyze and report on disk usage within directories and files. Whether you’re trying to identify space-hogging directories, manage disk space efficiently, or simply gain insights into storage consumption, the du command provides valu
5 min read
dump command in Linux with examples
The dump command in Linux is used for backing up the filesystem to a storage device. Unlike commands that back up individual files, dump operates on entire filesystems, transferring data to tape, disk, or other storage media for safekeeping. One of its key advantages is the ability to perform increm
6 min read
dumpe2fs command in Linux with examples
dumpe2fs command is used to print the super block and blocks group information for the filesystem present on device. Can be used with ext2/ext3/ext4 filesystem for information. The printed information may be old or inconsistent when it is used with a mounted filesystem. Don't forget to unmount your
2 min read
dumpkeys command in Linux with examples
'dumpkeys' command in Linux is used for the dump keyboard translation tables. It writes to the standard output and the current contents of the keyboard driver's translation tables in the format specified by Keymaps. Here, we’ll break down the syntax, options, and practical examples of using the dump
3 min read
echo command in Linux with Examples
The echo command in Linux is a built-in command that allows users to display lines of text or strings that are passed as arguments. It is commonly used in shell scripts and batch files to output status text to the screen or a file. Syntax of `echo` command in Linuxecho [option] [string]Here, [option
3 min read
ed command in Linux with examples
Linux 'ed' command is used to start the ed text editor, a very minimal fronted line-based text editor. The lines are very simple in relation to other text files, hence easy to work on, for creating as well as editing, display, and manipulation of files. Since it was the first editor that was include
4 min read
egrep command in Linux with examples
The 'egrep' command in Linux is a powerful pattern-searching utility that belongs to the family of grep functions. It functions similarly to 'grep -E' by treating patterns as extended regular expressions, allowing more complex pattern matching without the need to escape special characters. This comm
3 min read
eject command in Linux with examples
eject allows ejecting a removable media (typically a CD-ROM, floppy disk, tape, or JAZ or ZIP disk) using the software. You 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. Syntaxeject [...OPTIONS]The
4 min read
emacs command in Linux with examples
Introduction to Emacs Editor in Linux/Unix Systems: The Emacs is referred to a family of editors, which means it has many versions or flavors or iterations. The most commonly used version of Emacs editor is GNU Emacs and was created by Richard Stallman. The main difference between text editors like
5 min read
env command in Linux with Examples
The 'env' command in Linux is a versatile tool used to manage environment variables. It can print all the current environment variables, set new ones, or run a command within a custom environment. Additionally, 'env' is commonly used in shell scripts to launch the correct interpreter, ensuring the s
3 min read
eval command in Linux with Examples
eval is a built-in Linux command that executes arguments as a shell command. It combines arguments into a single string, uses it as input to the shell, and executes the commands. Syntaxeval [arg ...]Here, arg can be one or more arguments that eval will process and combine into a single shell command
2 min read
ex command in Linux with examples
ex (stands for extended) is a text editor in Linux which is also termed as the line editor mode of the vi editor. This editor simply provided some editing commands which has greater mobility. With the help of this editor, a user can easily move between files. Also, he/she has a lot of ways to transf
4 min read
exec command in Linux with examples
The 'exec' command in Linux is a powerful shell built-in used to replace the current shell process with a new command process. Unlike typical commands that create a new process, 'exec' transforms the existing process, directly impacting the efficiency and behavior of scripts. What is the exec Comman
3 min read
exit command in Linux with Examples
The 'exit' command is a fundamental command in Linux used to exit the current shell session. This command is widely used in scripting and command-line operations, allowing users and scripts to terminate a session or a process in a controlled manner. The 'exit' command can take an optional parameter
2 min read
expand Command in LINUX with examples
Whenever you work with files in LINUX there can be a situation when you are stuck with a file containing many tabs and whatever you need to do with a file requires that file with no tabs but with spaces. In this situation, the task looks quite simple if you are dealing with a small file but what if
3 min read
expect command in Linux with Examples
expect command or scripting language works with scripts that expect user inputs. It automates the task by providing inputs. // We can install expect command using following if not installed // On Ubuntu $sudo apt install expect // On Redhat based systems $ yum install expect First we write a script
2 min read
export command in Linux with Examples
The 'export' command is one of the essential built-in commands in the Bash shell, allowing users to manage environment variables effectively. It is defined in POSIX standards, which state that the shell will assign the export attribute to specified variables, causing them to be included in the envir
3 min read
expr command in Linux with examples
The expr command in Unix is a versatile tool used for evaluating expressions in the shell environment. It performs a wide range of functions, including arithmetic calculations, string operations, and comparisons based on regular expressions. What is the 'expr' Command?expr stands for "expression" an
3 min read
factor command in Linux with examples
The factor command in Linux is used to print the prime factors of the given numbers, either given from the command line or read from standard input. The numbers given through standard input may be delimited by tabs, spaces or newlines. Syntaxfactor [NUMBER]You can provide one or more numbers as argu
2 min read
fc Command in Linux with Examples
As we all know that LINUX is command friendly and while working on LINUX, you may deal with very long commands that may include long paths or really difficult syntax, and imagine what if working with such commands you do a minor mistake which will require re-writing of the entire command synopsis an
3 min read