Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 5 down vote accepted

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.

share|improve this answer
Rad, this is totally what I was looking for. Just tested it, works great! – aendrew 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.

share|improve this answer
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! – aendrew Jan 24 '14 at 14:58

You must log in to answer this question.

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