Answers:
这将递归遍历/path/to/folder
目录并仅列出符号链接:
ls -lR /path/to/folder | grep ^l
如果您也打算遵循符号链接,则应使用find
命令,但应包括该-L
选项;实际上,find
手册页中说:
-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
这可能会起作用:我在find
手册页中找到了该菱形:如果使用的是-type
选项,则必须将其更改为-xtype
选项:
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
find -L /var/www/ -xtype l
)中查看最终编辑。使用-xtype
而不是-type
应该可以解决您的问题。祝好运!
ls -laR /path/to/folder | grep ^l
,如果你也想的过程“隐藏的”点文件夹...
-xtype
中不可用。find . -type l
似乎正在递归检查。
find . -type l -ls
说明: find
从当前目录.
开始,所有-type l
墨水参考均已列出-ls
并详细列出。干净利落...
扩展此答案,以下是一些与符号链接有关的find
命令:
find . -lname link_target
请注意,link_target
该模式可能包含通配符。
find -L . -type l -ls
该-L
选项指示find
遵循符号链接,除非链接断开。
find -L . -type l -delete -exec ln -s new_target {} \;
find
可以在这里找到更多示例:https : //hamwaves.com/find/
find
都有一个-ls
选项。因此find . -type l -ls
应与上述等效。
find -lname '*/dir/*' -printf '%P -> %l\n'
。值得一提的是link_target是一种模式。
find
默认情况下已经递归查找:
[15:21:53 ~]$ mkdir foo
[15:22:28 ~]$ cd foo
[15:22:31 ~/foo]$ mkdir bar
[15:22:35 ~/foo]$ cd bar
[15:22:36 ~/foo/bar]$ ln -s ../foo abc
[15:22:40 ~/foo/bar]$ cd ..
[15:22:47 ~/foo]$ ln -s foo abc
[15:22:52 ~/foo]$ find ./ -type l
.//abc
.//bar/abc
[15:22:57 ~/foo]$
find
默认情况下会递归吗?我猜不是;)
-L
为在没有任何运气的情况下使用该标志进行查找-有任何猜测吗?
到目前为止,这是我发现的最好的事情-递归地向您显示当前目录中的符号链接,但不遵循它们,而是显示完整路径和其他信息:
find ./ -type l -print0 | xargs -0 ls -plah
输出看起来像这样:
lrwxrwxrwx 1 apache develop 99 Dec 5 12:49 ./dir/dir2/symlink1 -> /dir3/symlinkTarget
lrwxrwxrwx 1 apache develop 81 Jan 10 14:02 ./dir1/dir2/dir4/symlink2 -> /dir5/whatever/symlink2Target
etc...