Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

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

I am trying to find all the symbolic links on my system with name keytool. I use the below command :

ls -lR | grep keytool

It gives some results, but i want the directory names as well. So i use the -d option:

ls -ldR | grep keytool

But this gives me no results at all. This is probably because of the behaviour of -d option as described by --help :

-d : list directory entries instead of contents, and do not dereference symbolic links

So how do i get the directory names of the symbolic links?

share|improve this question
up vote 2 down vote accepted

Use find

Note: after some testing, the only way I found was to pipe the output to xargs and test the output of find

find / -name keytool -type l | xargs -L1 --null bash -c 'if [ -d $0 ]; then echo $0 ; fi'
share|improve this answer
Why not just use the built-in action -ls instead of -exec ls -l {} \;? – steeldriver Jul 11 '14 at 20:41
That returned me nothing – faizal Jul 11 '14 at 20:42
Now i get the error find: paths must precede expression: c – faizal Jul 11 '14 at 20:45
that returned me nothing as well..wierd – faizal Jul 11 '14 at 20:46
well, run find / -name keytool , the listing will show all matches. I am guessing none are both directories and symlinks – bodhi.zazen Jul 11 '14 at 20:51

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.