Skip to main content

How to list directory names that do not contain a certain filename? [Resolved]

I have several hundreds of directories and in each of these directories there are files with date in their filenames, like this:

$cd dir1
$ls 
20190915.file.gz
20190916.file.gz
20190917.file.gz
...

Sometimes it happens that a certain file does not get generated in a certain folder. Continuing from the previous example, file 20190916.file.gz might be missing in dir2:

$cd dir2
$ls
20190915.file.gz
20190917.file.gz
...

How could I list only directory names that do not contain 20190916.file.gz?

$find . | grep 20190916 would list all folders that do contain this file, so basically I only need to somehow reverse the output of this command


Question Credit: kamokoba
Question Reference
Asked September 21, 2019
Posted Under: Unix Linux
2 views
1 Answers

Assuming the directories are not nested, loop through the directories and check for the presence of the file in each directory.

for d in */; do
  if ! [ -e "$d/20190916.file.gz" ]; then
    echo "Missing $d/20190916.file.gz"
  fi
done

credit: Gilles
Answered September 21, 2019
Your Answer
D:\Adnan\Candoerz\CandoProject\vQA