0

The lndir command performs a shadow copy of a directory tree, but using symlinks. Files are symlinked rather than copied, while subdirectories are copied. It works fine, but I also need some kind of unlndir script that performs the opposite.

In other words, the behavior of unlndir would be:

  • If there's a symbolic link on the target tree pointing to a file in the source tree, remove the symbolic link.
  • Perform previous task recursively for all subdirectories that exist in both the source and the target tree.
  • If some subdirectory in the target tree becomes empty, remove it.

I realize this is similar to what GNU Stow does, but I am looking for a simpler shell-script based approach.

Do you know of any shell script that can do this?

1

Assuming GNU find(1):

find -P /some/dir -type l -xtype f -delete && find -P /some/dir -type d -empty -delete

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.