I have a 150 subfolders. Apparently 4 of them do not have files that should be in them, named PKA.dump

How can I run a command in linux to find which folders are missing the file PKA.dump?

  • Best idea I have atm is find looking for all directories which do have PKA.dump. Then the same for all directories. And compare those two files. (uniq might help with the last). – Hennes Apr 25 '15 at 20:54


Simple, it transpires. The following gets a list of directories with the cover and compares that with a list of all the second-level directories. Lines that appear in both "files" are suppressed, leaving a list of directories that need covers.

comm -3 \
    <(find ~/Music/ -iname 'cover.*' -printf '%h\n' | sort -u) \
    <(find ~/Music/ -maxdepth 2 -mindepth 2 -type d | sort) \
| sed 's/^.*Music\///'



  • comm's arguments are as follows:

    • -1 suppress lines unique to file1
    • -2 suppress lines unique to file2
    • -3 suppress lines that appear in both files
  • comm only takes files, hence the kooky <(...) input method. This pipes the content via a real [temporary] file.

  • comm needs sorted input or it doesn't work and find does by no means guarantee an order. It also needs to be unique. The first find operation could find multiple files for cover.* so there could be duplicate entries. sort -u quickly ruffles those down to one. The second find is always going to be unique.

  • dirname is a handy tool for getting a file's dir without resorting to sed (et al).

  • find and comm are both a bit messy with their output. The final sed is there to clean things up so you're left with Artist/Album. This may or may not be desirable for you.


You could list the folders to a file each (with ls -1 folder | sort > file1, etc), the run diff on the files. That will list you the differences between files:

Say I have 2 folders vc and vc2. I generate the lists like this:

ls -1 vc | sort > vc.txt
ls -1 vc2 | sort > vc2.txt

Then I can see the differences like this:

diff vc.txt vc2.txt

which produces:

< requirements.txt

which means that requirements.txt is missing ('<' indicates missing) from vc2.txt (second on the diff line).

  • How do I run diff on these files? – Jackson Hart Apr 27 '15 at 4:04
  • @JacksonHart edited the original reply with an example – jcoppens Apr 27 '15 at 4:31

Assuming you want to search one level of subdirectories, I recommend a simple Bash loop:

for f in * ; do [ -d "$f" -a ! -e "$f/PKA.dump" ] && echo "$f" ; done

That is, "for all (non-hidden) entries in this directory, if it's a directory and there doesn't exist a PKA.dump inside, print the name of the directory".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.