I'm new to Bash, and I'm trying to find files in a certain set of folders. I want to create a txt report for image files in each /check/ folder.
Here's what I've been working with:
# Find images
for f in */check/ ; do
find ./ -iname "*jpg*" -o -iname "*png*" > find_images.txt
echo "finished $f"
done
I can't figure out how to only look at subfolders named "check", and I also want to pass the variable so that I get separate text files named after the parent folders. Any suggestions?
Use grep command and pipe it with find command
The
find
command supports searching for directories (folders), e.g.You could use these results to then look for the files you want. The variable $f will be the name of the folder, so use that in the inner find command. Then if you want separate output files each time through the loop, use a variable in the filename. The $f variable will have slashes in the content, so you probably don't want to use that in the name of your output file. In my example, I use a counter to make sure each output file has a unique name.
You're close, but you're not using
$f
which contains the folder's name: