I need to check if multiple files (about 30) exist in multiple directories. The files have different prefixes (that match the name of the directory, e.g., sub1/sub1_file1.txt, sub2/sub2_file1.txt, sub3/sub3_file1.txt; sub1/sub1_file2.txt, sub2/sub2_file2.txt etc). I am using ls to achieve this and it works, however my script only prints whether the files exist or don't exist, but not which ones. In particular, I want to know which files do NOT exist in which directories. Could anyone help me? I am using bash. What I have so far is:
for d in */ ; do
cd "$d"
if ls *_file1.txt *_file2.txt *_file3.txt > /dev/null 2>&1; then
// nothing
else
echo "$d" "files do not exist" >> missingFiles.txt
fi
cd ..
done
In missingFiles.txt currently I have (for example)
sub1/ files do not exist
And I would like
sub1/ sub1_file1.txt do not exist
Thanks so much.
Edit: example of directory
sub1
|_sub1_file1.txt
|_sub1_file2.txt
|_sub1_file3.txt
sub2
|_sub2_file1.txt
|_sub2_file2.txt
|_sub2_file3.txt
sub3
|_sub3_file1.txt
|_sub3_file2.txt
I need to check whether all files (file1, file2, file3) are present or not in all the 'sub' directories. In the example, the script should return that sub3_file3.txt is missing (or file3 in sub3). There are also other files in each directory that I am not interested in checking.