I need to be able to find all sub-directories that are missing a specific file.

I have thousands of zip files that are being Ftp'd to my server within a specific directory on a daily basis: /opt/FTP/IN Now the sender is creating folders under that directory and placing zip files within the folders being created, there could be hundreds to thousands of folders created. However, when they are done placing zip files in a specific folder, they are supposed to create a file called done.txt to let us know that folder is ready to be processed. Sometimes they miss placing the done.txt file and I need to go in and manually create it.

How can I search for and only collect the folder names that do not contain the done.txt file?

  • Do the directories have any sort of tree structure, is it all flat?
    – tink
    Dec 16, 2018 at 2:11

1 Answer 1


Whichever is clearer to you:

Invert the find condition:

find /start/dir -type d ! -exec test -e {}/done.txt \; -print

Invert the test condition:

find /start/dir -type d -exec test ! -e {}/done.txt \; -print

Any directories that don't have a done.txt file in them are the printed.

  • "Fail the test" might be confusing wording; hopefully the intention is clear.
    – Jeff Schaller
    Dec 16, 2018 at 2:24
  • If you're using {} anyway, is -execdir needed?
    – muru
    Dec 16, 2018 at 5:11
  • Good point, @muru - thanks! I had started off initially thinking I needed to use execdir, but exec works perfectly. I'll update the Answer.
    – Jeff Schaller
    Dec 16, 2018 at 13:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .