Sign up ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sometimes my CD-ROM is mapped to /dev/sg0 and sometimes to /dev/sg1. How do I detect the currently mapped device in a bash script?

share|improve this question

1 Answer 1

up vote 0 down vote accepted

Assuming the cdrom is already mounted (it normally mounts automatically when a CD is inserted), just run the following command:

mount | grep ^'/dev/sg' | awk '{print $1}'
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.