Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

SSH is a soft link (symbolic link or symlink) to dropbear.

I want to know how many files are soft linked to dropbear. Is there any method to find how many soft links point to certain file?

It would be better if it also shows a list of soft links which point to that file.

/usr/bin/ssh -l
lrwxrwxrwx    1 root     root           16 Apr 22  2011 /usr/bin/ssh -> ../sbin/dropbear
share|improve this question

2 Answers 2

I came up with this chain:

find . -type l -ls | egrep -o -- '-> .+$' | sort | uniq -c

It lists all symbolic links, greps for whatever comes after ->, sorts it and groups it.

It is a first step, but by far not perfect. You can run find on / to get a big list, but if the symbolic link is to a relative target, the command will group them together even if they are not the same.

Example:

/home/shi/bin/list.sh -> ./show.sh
/home/shi/sbin/all.sh -> ./show.sh

show.sh might be different programs - one in bin and another one in sbin.

Another issue are regular file names with -> in them (not very common, though). The format of ls cannot distinguish this.

Example:

test.sh -> all.sh -> list.sh

A file called test.sh might link to all.sh -> list.sh or a file called test.sh -> all.sh might link to list.sh.

I hope this helps in your case. For a perfect solution you should use a script (sh, PHP, Perl).

share|improve this answer

If you don't need to check across filesystems you could use symlinks:

symlinks -rsv / | grep test_off.sh | tee >(wc -l)

the above should output a list of links that point to a file as well as count their number:

absolute: /usr/bin/test_off.sh -> /usr/share/acpi_call/test_off.sh
absolute: /root/linkone -> /usr/share/acpi_call/test_off.sh
relative: /root/rellinktwo -> ../usr/share/acpi_call/test_off.sh
3

man symlinks for more details.

share|improve this answer

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.