Search code examples
linuxbashshellsymlinkdelete-directory

Delete a symbolic link when the original folder is deleted


I was thinking of using inotifywait to watch the original folder where the original folders are in, then whenever it detects that a folder has been deleted, then delete the same symbolic link in the other folder.

So my question is, is that the best way? Or are there better ways to delete a symbolic link when the original folder gets deleted?


Solution

  • i have not used inotify, but if it can integrate *nix's find command, you can use it to delete the link

    find /folderpath -type l -delete