2

Does anyone know of some tool capable of keeping symbolic links valid in spite of renaming or moving of files or directories? If not, are there obvious reasons why this should be difficult to implement? I'm thinking of a daemon that could a) keep track of creation and deletion of symbolic links, maintaining a database of existing links; and b) keep track of renaming and moving of file system objects, to be able to search the database for affected links and automatically fix them. Cheers.

  • 1
    Huh? Wouldn't your daemon need to keep track of the linked files instead of the links? After all you not only plan to detect the invalid symbolic links but also "repair" them, right? Now what if your symbolic link points to some remote location? – phk Oct 27 '15 at 15:15
  • Are you just searching for hard links? Symbolic links aren't supposed to survive moving files. That's among the reasons why they're used. – terdon Oct 27 '15 at 15:42
  • 1
  • Thanks all. phk and Stéphane, I realise that a daemon like I described, if working blindly, could cause trouble: remote targets, targets without permission, targets that don't exist all the time, etc. I wonder if it could work, say, only for linking within a home directory. But I guess symbolic links simply aren't meant to be used this way, like terdon suggests. terdon, I really meant symbolic (soft) links, not hard links. If in the future hard links become allowed / safe for directories, I'll use them instead. – Telmo A. Oct 27 '15 at 16:20
1

This line of find command lists you all symbolic links that point to no file.

# Ask `find` to walk files in some/dir in this manner:
#   -L       Follow symlinks. Use symlink it self if its can't be followed
#   -type l  Only care about symlinks. So we only get failed symlinks from -L.
#   -ls      list current file in `ls -dils` format.

find -L some/dir -type l -ls

You may use this to find broken links, or links to files that "you" cannot read because of missing permissions. So run this command by a user with sufficient privilleges.

  • OK, I expect that the checks are done by a user with sufficient privileges. – schily Oct 27 '15 at 16:06
  • zsh glob equivalent: **/*(D-@). – Stéphane Chazelas Oct 27 '15 at 16:15
  • Thanks. What I had in mind was actually something running in the background that would (as much as possible) keep links valid, automatically. Actually, now I found a partially similar question in the forum: Keep tracking of symbolic links?. – Telmo A. Oct 27 '15 at 16:25

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.