简体   繁体   English

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

[英]How to find files excluding symbolic links?

I want to find files in Linux that follow a certain pattern but I am not interested in symbolic links.我想在 Linux 中找到遵循某种模式的文件,但我对符号链接不感兴趣。

There doesn't seem to be an option to the find command for that.似乎没有find命令的选项。

How shall I do ?我该怎么办?

Check the man page again ;) It's:再次检查手册页;) 它是:

find /path/to/files -type f

type f searches for regular files only - excluding symbolic links. type f仅搜索常规文件 - 不包括符号链接。

! -type l

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

find /usr/bin/ \! -type l

Do you want it to follow symlinks but not return them (if they match your pattern)?您是否希望它遵循符号链接但不返回它们(如果它们与您的模式匹配)?

find -H ? 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.

I have readed the MAN and now it seems is -P also, using -type r would raise an error.我已经阅读了 MAN,现在似乎也是 -P,使用 -type r 会引发错误。 also notice is the DEFAULT behavior now.还要注意的是现在的默认行为。

-P Never follow symbolic links. -P 从不遵循符号链接。 This is the default behaviour.这是默认行为。 When find examines or prints information a file, and the file is a symbolic link, the information used shall be taken from the properties of the symbolic link itself.当 find 检查或打印文件信息,并且该文件是一个符号链接时,所使用的信息应取自符号链接本身的属性。

This works for me:这对我有用:

find -H . -maxdepth 1 -type f

Actually, don't really need the -H实际上,真的不需要 -H

Like @AquariusPower say, the use of find -type f -xtype f solved my problem, and now I get only real files and not symbolic links anymore.就像@AquariusPower 说的那样,使用find -type f -xtype f解决了我的问题,现在我只得到真实文件,不再得到符号链接。

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

I got:我有:

-xtype c -xtype c
The same as -type unless the file is a symbolic link.-type相同,除非文件是符号链接。 For symbolic links: if the -H or -P option was specified, true if the file is a link to a file of type c ;对于符号链接:如果指定了-H-P选项,则如果文件是指向类型c的文件的链接,则为 true; if the -L option has been given, true if c is 'l'.如果已给出-L选项,则如果c为 'l',则为 true。 In other words, for symbolic links, -xtype checks the type of the file that -type does not check.换句话说,对于符号链接, -xtype检查-type不检查的文件-type

使用ls ,解决方法是:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何查找用户的文件和目录,并排除NFS挂载的NFS挂载和符号链接? - How to find files and directories for user and exclude NFS mount and symbolic links ot NFS mounts? 如何在多个符号链接中查找文件 - how to find files in multiple symbolic link 如何找到符号链接文件的相对路径? - how to find relative path to symbolic linked files? 如何以文件夹及其子文件夹的形式递归复制文件作为符号链接 - How to recursively copy files under a folder and its subfolders as symbolic links man找不到与符号链接指向的源文件相关的手册页 - man does not find man pages associated with the source files pointed to by symbolic links 查找不排除文件的统计信息 - Stat with find not excluding files 如何在LINUX的另一个目录中有选择地创建指向特定文件的符号链接? - How do I selectively create symbolic links to specific files in another directory in LINUX? 如何使用 qt 和 c++ 查找和删除坏或死的符号链接 - How to find and remove bad or dead symbolic links using qt and c++ 删除目录中的所有文件而不删除符号链接及其指向的文件 - Delete All Files In a Directory Without Deleting Symbolic Links and the Files They Point To 使用 linux find 命令查找目录和目录的符号链接 - Using linux find command to find directories and symbolic links to directories
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM