I have a large set of directories and files, along with many symlinks that typically point to a directory called "shared" or to a directory or a file underneath the "shared" directory.
Here is a representation:
$ ls -lR
total 0
drwxr-xr-x 5 myself staff 160 Oct 11 11:54 a
drwxr-xr-x 5 myself staff 160 Oct 11 11:55 b
./a:
total 0
lrwxr-xr-x 1 myself staff 2 Oct 11 11:54 a2 -> a1
lrwxr-xr-x 1 myself staff 2 Oct 11 11:54 a3 -> a2
lrwxr-xr-x 1 myself staff 2 Oct 11 11:54 a4 -> a3
./b:
total 0
lrwxr-xr-x 1 myself staff 2 Oct 11 11:54 b1 -> b2
lrwxr-xr-x 1 myself staff 2 Oct 11 11:54 b2 -> b3
lrwxr-xr-x 1 myself staff 2 Oct 11 11:55 b3 -> b4
If I use find -type l to list the symlinks, I get this long output:
$ find . -type l -ls
14800041 0 lrwxr-xr-x 1 myself staff 2 Oct 11 11:54 ./a/a4 -> a3
14800032 0 lrwxr-xr-x 1 myself staff 2 Oct 11 11:54 ./a/a3 -> a2
14799990 0 lrwxr-xr-x 1 myself staff 2 Oct 11 11:54 ./a/a2 -> a1
14800060 0 lrwxr-xr-x 1 myself staff 2 Oct 11 11:54 ./b/b2 -> b3
14800061 0 lrwxr-xr-x 1 myself staff 2 Oct 11 11:55 ./b/b3 -> b4
14800046 0 lrwxr-xr-x 1 myself staff 2 Oct 11 11:54 ./b/b1 -> b2
If I do a recursive listing with ls -lR, I get a similar output.
I just need the two bits in my output – the symlink name and what it points to, separated by ->. How can I get this output without having to use filters to parse ls or find output?
>Solution :
You could try
find . -type l -printf '%p -> %l\n'
Or if the -printf is not available you can also try
find . -type l -exec sh -c 'for link; do echo "$link -> $(readlink "$link")"; done' sh {} +
Hope it will help