如何查找不包括符号链接的文件?

时间:2013-04-30 15:22:10

标签: linux find symlink

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

find命令似乎没有选项。

我该怎么办?

7 个答案:

答案 0 :(得分:67)

再次检查man page;)它是:

find /path/to/files -type f

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

答案 1 :(得分:16)

! -type l

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

find /usr/bin/ \! -type l

答案 2 :(得分: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.

答案 3 :(得分:2)

我已经引用了MAN,现在看起来似乎是-P 另外,使用-type r会引发错误。 现在也注意到DEFAULT行为。

  

-P切勿关注符号链接。这是默认行为。找到检查或打印时                 信息文件,文件是符号链接,所用信息应取自                 符号链接本身的属性。

答案 4 :(得分:0)

这对我有用:

WITH RECURSIVE minmax AS
(
    SELECT MIN(CAST(time AS DATE)) AS min, MAX(CAST(time as DATE)) AS max
    FROM emp_time
),
dates AS
(
    SELECT m.min as datepart
    FROM minmax m
    RIGHT JOIN emp_time e ON m.min = CAST(e.time as DATE)
    UNION ALL
    SELECT d.datepart + 1 FROM dates d, minmax mm 
    WHERE d.datepart + 1 <= mm.max
)
SELECT d.datepart as date, e.emp, MIN(e.time) as intime, MAX(e.time) as outtime FROM dates d
LEFT JOIN emp_time e ON d.datepart = CAST(e.time as DATE)
GROUP BY d.datepart, e.emp
ORDER BY d.datepart;

实际上,不需要-H

答案 5 :(得分:0)

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

来自:upload

我得到了:

  

-xtype c       除非文件是符号链接,否则与-type相同。对于符号链接:如果指定了-H或-P选项,则如果文件是a,则为true   链接到c类型的文件;如果给出了-L选项,则为c,如果为c,则为true   是'我'。换句话说,对于符号链接,-xtype检查其类型   -type不检查的文件。

感谢。

答案 6 :(得分:0)

使用 ls,解决方法是:

ls <path> | grep -v '\->'