Tuesday, 27 October 2009

"What links here" for symlinks?

Ever been frustrated by knowing that you have created a link to your `pwd` 'somewhere' on the file system, but you are unable to remember where?

Ever wished you could just hit "What links here" to discover the location of the symlink from the target?

Tough.

There is no good solution.


Here are some ugly hacks:

#!/bin/bash
for file in `find / -type l 2> /dev/null`; do
ls $file -l 2> /dev/null | grep "target" 2> /dev/null
done


or

find ./ -type l -exec ls -l '{}' \; | awk '{print $11}' | grep "target"


These 'hacks' will thrash your disk, but what are you going to do? Unless we can make a file system based on a wiki ... (imagine a history page for all your config files?) or a database ... (imagine querying for all the files greater than 1 Gb older than 1 year?) we are stuck with these... Unless you know better?

No comments: