如何使用 GNU find 命令一次匹配多种文件类型(一个搜索命令)?
手册页说:
-type c
File is of type c:
b block (buffered) special
c character (unbuffered) special
d directory
p named pipe (FIFO)
f regular file
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.
s socket
D door (Solaris)
Run Code Online (Sandbox Code Playgroud)
我想搜索文件 ( f
) 和符号链接 ( l
) 并将其通过管道传输到另一个进程。如何同时搜索两者?
我试过了
find -type fl | …
find -type f -type l | …
find -xtype f -type l | …
Run Code Online (Sandbox Code Playgroud)
我知道一种解决方法是使用子shell
(find -type f; find -type l) | …
Run Code Online (Sandbox Code Playgroud)
但我只是想知道,如果它是可能的。
您可以对 find 进行分组和使用逻辑运算符,但您必须转义括号,以便您可以查找所有文件和链接,例如
find \( -type f -o -type l \) <other filters>
Run Code Online (Sandbox Code Playgroud)
因此,如果您想要名称以 t 开头的所有文件和链接,您可以这样做
find \( -type f -o -type l \) -name 't*'
Run Code Online (Sandbox Code Playgroud)
如果您想对事物进行分组并与其他运算符组合,您只需要括号,因此如果您没有其他搜索条件,则可以省略它们
归档时间: |
|
查看次数: |
156 次 |
最近记录: |