[英]Linux find command shell expansion
我有一个小问题,我不理解find命令。
我可以做这个 :
[root@hostnaoem# ❯❯❯ls /proc/*/fd
但这给了我一个错误:
[root@hostnaoem# ❯❯❯ find /proc/*/fd -ls
find: `/proc/*/fd': No such file or directory
即使我使用“/ proc / / fd” , / proc /“ ”/ fd或“/ proc / * / fd”
我已经搜索过, 发现 shell扩展说了这些,但我一无所获。 有人可以告诉我为什么吗?
谢谢
如果您只是RTFM,您将了解到find的语法是:
find [-H] [-L] [-P] [-D debugopts] [-Olevel] [path...] [expression]
通常使用的子集是:
find whereToSearch (-howToSearch arg)*
要在/proc
找到名为fd
所有文件|目录:
find /proc -name fd
-name
是最常见的howToSearch表达式:
-name模式
Base of file name (the path with the leading directories removed) matches shell pattern pattern. The metacharacters (`*', `?', and `[]') match a `.' at the start of the base name (this is a change in findutils-4.2.2; see section STANDARDS CON‐ FORMANCE below). To ignore a directory and the files under it, use -prune; see an example in the description of -path. Braces are not recognised as being special, despite the fact that some shells including Bash imbue braces with a special meaning in shell patterns. The filename matching is performed with the use of the fnmatch(3) library function. Don't forget to enclose the pattern in quotes in order to protect it from expansion by the shell.
(注意最后一句)
如果你的模式包含斜杠,你需要-path
或-wholename
(同样的东西):
find /proc/ -wholename '/proc/[0-9]*/fd' 2>/dev/null
您可能想要使用的其他表达式是:-type -depth,-mindepth,-maxdepth -user,-uid
请参阅find(1)以了解有关每个搜索表达式的更多信息。 如果要搜索终端内手册( man find
或man 1 find
),可以使用/
字符进入搜索模式(如大多数GUI应用程序中的Ctrl+F
)。
使用具有globbing( *
)的ls
通常是代码气味。 除非使用-d
标志,否则它将列出除匹配之外与glob模式匹配的目录的内容。 我发现echo globpattern
表单通常更方便查看glob模式匹配的结果。
这项工作:
[root@hostname # ❯❯❯ find /proc/ -path /proc/*/fd -ls
问候。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.