如何找到所有的符号链接的目录树? [英] How do I find all of the symlinks in a directory tree?
问题描述
我试图找到我的网站目录树中的所有符号链接。我知道,我可以使用找到
来做到这一点,但我无法弄清楚如何递归查询目录。
I'm trying to find all of the symlinks within a directory tree for my website. I know that I can use find
to do this but I can't figure out how to recursively check the directories.
我目前使用的命令是
find /var/www/ -type l
我如何得到这个检查子目录?
的更新:的
我刚刚发现,在/ var / WWW的内容是符号链接。我已经改变了命令
I just discovered that the contents in /var/www are symlinks. I've changed the command to
find -L /var/www/ -type l
和它需要一段时间才能运行,但我越来越不匹配。
and it take a while to run, however I'm getting no matches.
推荐答案
这将递归遍历 /路径/要/文件夹
目录只列出符号链接:
This will recursively traverse the /path/to/folder
directory and list only the symbolic links:
ls -lR /path/to/folder | grep ^l
如果你的目的是要遵循符号链接过多,你应该用你的找到
命令,但你应该包括 -L
选项;事实上找到
手册页说:
If your intention is to follow the symbolic links too, you should use your find
command but you should include the -L
option; in fact the find
man page says:
-L Follow symbolic links. When find examines or prints information
about files, the information used shall be taken from the prop‐
erties of the file to which the link points, not from the link
itself (unless it is a broken symbolic link or find is unable to
examine the file to which the link points). Use of this option
implies -noleaf. If you later use the -P option, -noleaf will
still be in effect. If -L is in effect and find discovers a
symbolic link to a subdirectory during its search, the subdirec‐
tory pointed to by the symbolic link will be searched.
When the -L option is in effect, the -type predicate will always
match against the type of the file that a symbolic link points
to rather than the link itself (unless the symbolic link is bro‐
ken). Using -L causes the -lname and -ilname predicates always
to return false.
那就试试这个:
find -L /var/www/ -type l
这可能会工作:如果您使用的是型
找到手册页这颗钻石发现>选项,您必须将其更改为 -xtype
选项:
This will probably work: I found in the find
man page this diamond: if you are using the -type
option you have to change it to the -xtype
option:
l symbolic link; this is never true if the -L option or the
-follow option is in effect, unless the symbolic link is
broken. If you want to search for symbolic links when -L
is in effect, use -xtype.
然后:
find -L /var/www/ -xtype l
这篇关于如何找到所有的符号链接的目录树?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!