如何使用 bash find 命令查找多个文件名?
$ find /path/* -type f -name pattern
模式应该匹配文件名列表:
- fname1.jpg
- fname2.png
- 我的文件.css
- 例子.gif
我试过
https://alvinalexander.com/linux-unix/linux-find-multiple-filenames-patterns-command-example 查找多个文件名命令:查找三个文件扩展名
find . -type f \( -name "*cache" -o -name "*xml" -o -name "*html" \)
而且有效。
无论如何,我认为使用 -name 模式比使用 -names 列表更清晰。
来自 $ 寻找
-name pattern
我正在寻找类似的东西:-name '[fname2.png|myfile.css|example.gif ]'
最佳答案
-regex
替代方案如下所示:
find . -type f -regextype posix-egrep -regex ".+\.(jpg|png|css)$"
关于-name
选项:
-name pattern
- Base of file name (the path with the leading directories removed) matches shell pattern.
Shell 模式不是成熟的 regex 模式。
关于regex - 使用查找实用程序匹配多个文件名的模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48841090/