Is there a way to check if there are symbolic links pointing to a directory?

跟風遠走 提交于 2019-11-28 15:34:23

I'd use the find command.

find . -lname /particular/folder

That will recursively search the current directory for symlinks to /particular/folder. Note that it will only find absolute symlinks. A similar command can be used to search for all symlinks pointing at objects called "folder":

find . -lname '*folder'

From there you would need to weed out any false positives.

JJK

You can audit symlinks with the symlinks program written by Mark Lord -- it will scan an entire filesystem, normalize symlink paths to absolute form and print them to stdout.

There isn't really any direct way to check for such symlinks. Consider that you might have a filesystem that isn't mounted all the time (eg. an external USB drive), which could contain symlinks to another volume on the system.

You could do something with:

for a in `find / -type l`; do echo "$a -> `readlink $a`"; done | grep destfolder

I note that FreeBSD's find does not support the -lname option, which is why I ended up with the above.

no1uknow
find . -type l -printf '%p -> %l\n'
stephanea

Apart from looking at all other folders if there are links pointing to the original folder, I don't think it is possible. If it is, I would be interested.

bfabry
find / -lname 'fullyqualifiedpathoffile'
Lunar Mushrooms
find /foldername -type l -exec ls -lad {} \;
paxdiablo

For hardlinks, you can get the inode of your directory with one of the "ls" options (-i, I think).

Then a find with -inum will locate all common hardlinks.

For softlinks, you may have to do an ls -l on all files looking for the text after "->" and normalizing it to make sure it's an absolute path.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!