I have a big bunch of directories, each with a series of .pdf files. Some of these files have successfully converted to .csv, some have not. An example directory listing using find ./:


How would I return a list of files that have not successfully converted?

In other words, what are the files that don't have a .csv.pdf counterpart?

In this example, it would be test{6,7,8}.pdf.


Here's how it works with find:

find . -name "*.pdf" | while read F; do test -f "${F}.csv" || echo "$F"; done

Using find is preferable to shell globbing as it has no limitation on the number of arguments and it works with spaces and special characters.

  • Rad, this is totally what I was looking for. Just tested it, works great!
    – aendra
    Jan 23 '14 at 20:52

I couldn't find a way to do it with find directly, but it's very easy using a for loop:

for file in *.pdf; do [ -f ${file}.csv ] || echo $file; done

If you need to run it at the top directory and have it recurse, you could use find like this:

for file in $(find . -iname '*.pdf'); do [ -f ${file}.csv ] || echo $file; done

which would output something like this:


Careful with that last one though, if you aren't sure there won't be any strange characters in the input filenames, make sure you set IFS environment variable accodingly:

export IFS=$'\n'

Of course, from here on it only gets nastier.

I'm assuming you use bash.

  • This is a great, detailed answer if you have a less-than-stellar version of find (I think it's a bit different on Solaris) or don't like find -- I accepted the other answer because it's closer to my initial question, but this one is pretty terrific as well. Wish I could accept both!
    – aendra
    Jan 24 '14 at 14:58

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.