linux如何在特定文件夹中查找特定文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18849837/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
linux how to find specific files in specific folders
提问by user1880957
This is my folder structure:
这是我的文件夹结构:
/site1/myFolder/otherFolder1/a.gif
/site1/myFolder/otherFolder1/a.gif
/site1/myFolder/otherFolder1/b.png
/site1/myFolder/otherFolder1/b.png
/site1/myFolder/otherFolder1/c.php
/site1/myFolder/otherFolder1/c.php
...
...
/site2/myFolder/otherFolder2/d.gif
/site2/myFolder/otherFolder2/d.gif
/site2/myFolder/otherFolder2/e.png
/site2/myFolder/otherFolder2/e.png
/site2/myFolder/otherFolder2/f.php
/site2/myFolder/otherFolder2/f.php
...
...
/site3/myFolder/otherFolder3/g.gif
/site3/myFolder/otherFolder3/g.gif
/site3/myFolder/otherFolder3/h.png
/site3/myFolder/otherFolder3/h.png
/site3/myFolder/otherFolder3/i.php
/site3/myFolder/otherFolder3/i.php
...
...
Got this far:
走到这一步:
find /var/www/html -type d -name myFolder -exec find {} -name "*.php" \;
for i in `find /var/www/html -type d -name myFolder -exec find {} -name "*.php" \;`
do
some_house_keeping_here
done
But I want to do something like this:
但我想做这样的事情:
find /var/www/html -type d -name myFolder -exec find {} -name "*.php" -exec do_some_housekeeping {} \; \;
采纳答案by Hari Menon
You can use the -path
option instead of -name
. It would match the entire absolute path with the regex.
您可以使用该-path
选项代替-name
。它会将整个绝对路径与正则表达式匹配。
find /var/www/html -path "*/myFolder/*.php" -exec do_some_housekeeping {} \;
回答by Nicu Stiurca
There is a -path
flag that would probably help a lot.
有一个-path
标志可能会有很大帮助。
find /var/www/html -path "myFolder/otherFolder?" -name "*.php" -exec do_some_housekeeping {} \;