87

我想在 Linux 中查找遵循某种模式的文件,但我对符号链接不感兴趣。

该命令似乎没有选项find

我该怎么办?

4

7 回答 7

108

再次检查手册页;)它是:

find /path/to/files -type f

type f仅搜索常规文件 - 不包括符号链接。

于 2013-04-30T15:28:30.250 回答
32
! -type l

例如,如果要搜索 /usr/bin 中的所有常规文件,不包括符号链接:

find /usr/bin/ \! -type l
于 2015-06-25T15:38:44.213 回答
3

您是否希望它遵循符号链接但不返回它们(如果它们与您的模式匹配)?

find -H?

man find
     ...
     -H      Cause the file information and file type (see stat(2)) returned for each symbolic link specified on the command line to be those of
             the file referenced by the link, not the link itself.  If the referenced file does not exist, the file information and type will be
             for the link itself.  File information of all symbolic links not on the command line is that of the link itself.

     -L      Cause the file information and file type (see stat(2)) returned for each symbolic link to be those of the file referenced by the
             link, not the link itself.  If the referenced file does not exist, the file information and type will be for the link itself.

             This option is equivalent to the deprecated -follow primary.
于 2013-04-30T15:29:14.067 回答
3

我已经阅读了 MAN ,现在似乎也是 -P ,使用 -type r 会引发错误。还要注意现在的默认行为。

-P 从不遵循符号链接。这是默认行为。当 find 检查或打印文件信息时,该文件是符号链接,所使用的信息应取自符号链接本身的属性。

于 2015-07-01T01:10:36.830 回答
0

这对我有用:

find -H . -maxdepth 1 -type f

实际上,并不需要 -H

于 2016-10-12T21:39:28.757 回答
0

就像@AquariusPower 说的那样,使用 find -type f -xtype f 解决了我的问题,现在我只得到真实文件而不是符号链接了。

来自:https ://linux.die.net/man/1/find

我有:

-xtype c
-type除非文件是符号链接相同。对于符号链接:如果指定了-Hor-P选项,如果文件是指向c类型文件的链接,则为 true ;如果-L已给出选项,则如果c 为“l”,则为 true。换句话说,对于符号链接,-xtype检查-type不检查的文件的类型。

于 2018-05-17T19:54:18.003 回答
0

使用ls,解决方法是:

ls <path> | grep -v '\->'
于 2021-06-08T03:07:05.107 回答