Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

On my Ubuntu Natty, typically all new drives inserted (e.g. USB Flash thumbdrives) are mounted under /media. So, on my system, I can do something like this:

$ mount | grep '/media'
/dev/sda6 on /media/disk1 type ext4 (rw,uhelper=hal,commit=0)
/dev/sda9 on /media/disk2 type ext4 (rw,nosuid,nodev,uhelper=udisks,commit=0)

# create proper dir
$ sudo mkdir /media/properdir
# creat symlink
$ sudo ln -s /tmp /media/

$ ls -la /media/
total 24
drwxr-xr-x  6 root          root          4096 2013-04-08 16:35 .
drwxr-xr-x 22 root          root          4096 2013-03-23 21:44 ..
drwxr-xr-x 36 username      username      4096 2013-04-06 19:15 disk2
drwxr-xr-x 11 username      username      4096 2012-04-10 12:24 disk1
drwxr-xr-x  2 root          root          4096 2013-04-08 16:35 properdir
lrwxrwxrwx  1 root          root             4 2013-04-08 16:35 tmp -> /tmp

... that is, ls doesn't distinguish between a "proper" directory, and a mount point for a drive. What I'd like to have, is a tool output possible mount points as well, similar to how a symlink is shown by ls; example:

$ lsMOUNT -la /media/
total 24
drwxr-xr-x  6 root          root          4096 2013-04-08 16:35 .
drwxr-xr-x 22 root          root          4096 2013-03-23 21:44 ..
drwxr-xr-x 36 username      username      4096 2013-04-06 19:15 disk2 => /dev/sda9
drwxr-xr-x 11 username      username      4096 2012-04-10 12:24 disk1 => /dev/sda6
drwxr-xr-x  2 root          root          4096 2013-04-08 16:35 properdir
lrwxrwxrwx  1 root          root             4 2013-04-08 16:35 tmp -> /tmp

Does the proper ls have an option for something like this? If not, are there tools that can accept the same command line arguments as ls, but resolve potential mount points?

share|improve this question

1 Answer 1

That would be a nice feature. You may ask the ls people to consider that. :-)

Until they do that you will have to write your own script (you may alias to ls then) which checks for every outputdir whether it's a mountpoint. For single directories this can be done with the command mountpoint but for long listings I would suggest to optimize: Read the mount points from /proc/mounts, then call ls (with --quoting-style= set in a way that allows you to reliably parse the output) and then check the directory name of each line or entry against the mountpoint list. For matches you just append your favourite symbol.

share|improve this answer

Your Answer

 
discard

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.