简体   繁体   English

Linux在所有相似的路径中查找文件

[英]Linux find files in all similar paths

I have many Wordpress sites on a server. 我在服务器上有许多Wordpress网站。 How can I use find command to eg find all .htaccess files in all root directories? 如何使用find命令在所有根目录中找到所有.htaccess文件? Say I have a folder /var/www/html and in there I have all sites 说我有一个文件夹/ var / www / html,那里有所有站点

/var/www/html/site1/html/
/var/www/html/site2/html/
/var/www/html/site3/html/

Now I would like to find all files in each sites "wp-content" catalog. 现在,我想在每个站点的“ wp-content”目录中找到所有文件。 And see if there is a text in each file. 并查看每个文件中是否有文本。

Find all files ".htaccess" in all sites "wp-content" catalog, and check if the files contain the text "foobar-1" 在所有站点“ wp-content”目录中找到所有文件“ .htaccess”,并检查文件是否包含文本“ foobar-1”

I can check this is specific catalogs but want to find in all the folders with the same name in all sites 我可以检查这是特定的目录,但要在所有站点中的所有具有相同名称的文件夹中找到

find . -name ".htaccess" | grep "foobar-1"

If I've understood properly, and you only want to check in the wp-content directory itself (not subdirectories), and if all the site structures are the same, something like this should show all the names of all the .htaccess files that contain foobar-1 : 如果我已正确理解,并且您只想签入wp-content目录本身(而不是子目录),并且如果所有站点结构都相同,则类似这样的内容应显示所有.htaccess文件的所有名称。包含foobar-1

grep -l "foobar-1" /var/www/html/*/html/wp-content/.htaccess

If you also need to check subdirectories, or if the site structures differ (eg sometimes you run WordPress out of a subdirectory) you're on the right track with find 如果您还需要检查子目录,或者站点结构不同(例如,有时您在子目录中运行WordPress),则可以通过find正确的位置

find /var/www/html -name ".htaccess" -exec grep - "foobar-1" {} \;

Both of those are untested, but hopefully they'll point you in the right direction if I've made a typo. 两者都未经测试,但希望如果我输入错误,它们会为您指明正确的方向。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM