Find files in multiple folder names
And if you want to search three folders named foo
, bar
, and baz
for all *.py
files, use this command:
find foo bar baz -name "*.py"
so if you want to display files from dir1
dir2
dir3
use find dir1 dir2 dir3 -type f
try this find . \( -name "dir1" -o -name "dir2" \) -exec ls '{}' \;
It's best to use the -path directive:
find . \( -type f -and -path '*/dir1/*' -or -path '*/dir2/*' -or -path '*/dir3/*' -or -path '*/dir4/*' \)
Which means: find all files under current directory where there's 'dir1' or 'dir2' or 'dir3' or 'dir4' in the path.
Just to let everyone know. Adding .*/
before each dir
solved the problem since the regex
is matching against the full path it seems.