Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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

1 Answer 1

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 at 20:41
    
That returned me nothing –  faizal Jul 11 at 20:42
    
Now i get the error find: paths must precede expression: c –  faizal Jul 11 at 20:45
    
that returned me nothing as well..wierd –  faizal Jul 11 at 20:46
1  
well, run find / -name keytool , the listing will show all matches. I am guessing none are both directories and symlinks –  bodhi.zazen Jul 11 at 20:51

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.