Unix 查找:多种文件类型
我想对多种文件类型运行 find -name 。 例如。
find -name *.h,*.cpp
这可能吗?
I want to run find -name with multiple file types.
Eg.
find -name *.h,*.cpp
Is this possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
要在
man
页面中查找此信息,请键入man find
并通过键入/OPERATORS
搜索运算符并按 Enter 键。.
对于 GNU find 来说并不是严格必需的,但在 Unix 中是必需的。在这两种情况下,引号都很重要,如果这些类型的文件出现在当前目录中,则将它们省略将导致错误。在某些系统(例如 Cygwin)上,需要括号来使扩展集包含在内:
To find this information in the
man
page, typeman find
and the search for operators by typing/OPERATORS
and hit enter.The
.
isn't strictly necessary with GNU find, but is necessary in Unix. The quotes are important in either case, and leaving them out will cause errors if files of those types appear in the current directory.On some systems (such as Cygwin), parentheses are necessary to make the set of extensions inclusive:
这就是我用的
Thats what I use
您还可以使用 -regex 实用程序:
find -E 。 -iregex ".*\.(js|jsx|html|htm)"
请记住,正则表达式查看完整的绝对路径:
有关带有测试用例的正则表达式的说明,请查看:https://regex101.com/r/oY1vL2/1
-E
(作为路径之前的标志)启用扩展(现代)正则表达式。这适用于 BSD
find
(Mac OSX 10.10.5)You can also use the
-regex
utility:find -E . -iregex ".*\.(js|jsx|html|htm)"
Remember that the regex looks at the full absolute path:
For an explanation of that regex with test cases check out: https://regex101.com/r/oY1vL2/1
-E
(as a flag BEFORE the path) enables extended (modern) regular expressions.This is for BSD
find
(Mac OSX 10.10.5)对我有用。
works for me.
适用于搜索文件。
用于在它们上执行命令
works for searching files.
works for executing commands on them
这就是我使用的。我强烈推荐“-regextype posix-extended”参数。
That's what I use.I strongly recommend the "-regextype posix-extended" argument.