16.28 oldlinks: Find Unconnected Symbolic LinksOne problem with symbolic links is that they're relatively "fragile" ( 18.6 ) . The link and the file itself are different kinds of entities; the link only stores the name of the "real" file. Therefore, if you delete or rename the real file, you can be left with a "dead" or "old" link: a link that points to a file that doesn't exist. This causes no end of confusion, particularly for new users. For example, you'll see things like this:
% The file's obviously there, but cat tells you that it doesn't exist. There's no real solution to this problem, except to be careful. One way to be careful is to write a script that checks links to see whether or not they exist. Here's one such script from Tom Christiansen; it uses find to track down all links, and then uses perl ( 37.1 ) to print the names of links that point to nonexistent files.
#!/bin/sh find . -type l -print | perl -nle '-e || print' The script only lists "dead" links; it doesn't try to delete them or do anything drastic. If you want to take some other action (like deleting these links automatically), you can use the output of the script in backquotes ( 9.16 ) . For example:
% - |
|