Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

linux how to find specific files in specific folders [closed]

Tags:

This is my folder structure:

/site1/myFolder/otherFolder1/a.gif

/site1/myFolder/otherFolder1/b.png

/site1/myFolder/otherFolder1/c.php

...

/site2/myFolder/otherFolder2/d.gif

/site2/myFolder/otherFolder2/e.png

/site2/myFolder/otherFolder2/f.php

...

/site3/myFolder/otherFolder3/g.gif

/site3/myFolder/otherFolder3/h.png

/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 {} \; \; 
like image 860
user1880957 Avatar asked Sep 17 '13 12:09

user1880957


People also ask

How do I search for a file in a specific folder?

Click the Start button, type the file name or keywords with your keyboard, and press Enter. The search results will appear. Simply click a file or folder to open it.

How do I search only directories in a specific directory?

You can use combination of ls command, find command, and grep command to list directory names only. You can use the find command too.


2 Answers

You can use the -path option instead of -name. It would match the entire absolute path with the regex.

find /var/www/html -path "*/myFolder/*.php" -exec do_some_housekeeping {} \; 
like image 75
Hari Menon Avatar answered Oct 04 '22 04:10

Hari Menon


There is a -path flag that would probably help a lot.

find /var/www/html -path "myFolder/otherFolder?" -name "*.php" -exec do_some_housekeeping {} \; 
like image 36
Nicu Stiurca Avatar answered Oct 04 '22 03:10

Nicu Stiurca