Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I use just one single ls command to display all symbolic links in my /dev directory?

I know ls -l and that's about it.

share|improve this question

The normal way to do this would be to use find, if it is available. With GNU find (and possibly others), you can do:

find /dev -type l -ls

where the -type l condition says match only symbolic links. This will give you output like (copying just a few lines here):

1971    0 lrwxrwxrwx   1 root     root           10 Mar 25 19:29 /dev/disk/by-uuid/593596f4-a5a1-4e87-b985-b0196c2a067b -> ../../sda3
1952    0 lrwxrwxrwx   1 root     root           10 Mar 25 19:31 /dev/disk/by-uuid/7db08eaf-1d68-4aa3-a8e0-7e62489efb0f -> ../../sdb1
1933    0 lrwxrwxrwx   1 root     root           10 Mar 25 19:29 /dev/disk/by-uuid/a2d18bff-a710-43a8-b41a-fb39b814a165 -> ../../sda1
4209    0 lrwxrwxrwx   1 root     root           10 Mar 26 08:22 /dev/disk/by-path/pci-0000:00:12.2-usb-0:3:1.0-scsi-0:0:0:0-part1 -> ../../sdc1

You can replace the -ls action with whatever you prefer (-print and -exec spring to mind as useful).

Other than that, I suppose you could use something like ls -l /dev/disk/by-id | grep ^l, but parsing the output of ls is generally a bad idea.

share|improve this answer

ls -l | grep ^l

Generate a full listing, and select.

The other solution offered (find /dev -type l -ls) might be more efficient as it doesn't do the full listing, but it invokes 'ls' multiple times so it maybe less efficient. I'd bet less efficient, but also 'grep' is VERY useful and everyone should understand 'command | grep XXX".

You can use find and only invoke 'ls' once, but it gets more complicated... using xargs or backticks

ls -l `find /dev -type l`

or maybe something like

find /dev -type l -print0 | xargs -0 -L99 ls -l

but it's too ugly for beginners (-L 99 is not ideal, but I don't see how to do all args).

share|improve this answer
Another way of running ls only once: find /dev -type l -exec ls -l {} +. – pabouk Nov 14 '13 at 16:45
find ... -ls does not invoke the ls binary at all. For proof, try something like strace find . -ls 2>&1 | grep ls and notice the fact that there are no ls invocations prior to the output being printed. (strace prints all system calls made by an application, starting at its own call to execute the given command.) Now, something along the lines of find ... -exec ls '{}' ';' (and possibly even with +, depending on the number of files involved) is different, but that's not what you are talking about. – Michael Kjörling Nov 15 '13 at 13:58

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.