Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

A cleanup Perl script running periodically deletes old log files, and if the folder is empty, it deletes the folder as well. Unfortunately, there is one exception: it should not delete a directory that is symlinked to.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
3.2k views
Welcome To Ask or Share your Answers For Others

1 Answer

There's no way to tell if there exists a symlink that directly references a dir. (Same for indirect references.)

The best you could do is check every single file on the entire file system, but even that monumental effort wouldn't be perfect. For example, it won't find symlinks on devices that aren't currently mounted, it won't find foreign symlinks to shared portions of the file system, etc.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...