1

I want to display info about symlinks and their target files without unnecessary (for this task) information. So far the best I found is to use this variation of find:

find -L /path/to/dir/ -xtype l -exec ls -al {} \;

This will output something like this:

lrwxr--r-- 1 user user 34 Feb 19 09:49 ./testdir1/slink1 -> /test/file.txt
lrwxr--r-- 1 user user 45 Feb 19 10:02 ./testdir1/slink2 -> /test/test2/file2.txt

Is there any possible way to get rid of permissions info, date of modification, etc., like below:

./testdir1/slink2 -> /test/test2/file2.txt

2

One way, just using pure find solution.

find /path/to/file -type l -printf '%-40p  --> %l\n

Just remove the -40 or adjust to desired output.

|improve this answer|||||
2

Try the readlink command.

e.g. (adapting your find command):

find -L /path/to/dir/ -xtype l -exec readlink {} \;

or, to get it as source -> target

find -L . -xtype l -print0 | xargs -0 -I{} bash -c 'echo {} "->" "$(readlink {} )"'
|improve this answer|||||
  • Thanks for your response, but readlink gives only paths to target files – Bieroed Feb 19 at 11:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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