The Wayback Machine - https://web.archive.org/web/20250114215732/https://www.geeksforgeeks.org/eject-command-in-linux-with-examples/
Open In App

eject command in Linux with examples

Last Updated : 25 Sep, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

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!


Next Article

Similar Reads

three90RightbarBannerImg