Sign up ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have many PDF files on one folder.

Is it possible check if one or more files are corrupted (zero pages, or unfinished downloads) using the command line, without needing to open them one by one?

share|improve this question

3 Answers 3

up vote 9 down vote accepted

Perhaps running pdfinfo (here on Fedora in the poppler-utils package) gives a clue?

Most of the information on a PDF file is in the dictionary at end, so if it finds it it should be OK. I'd do something like:

for f in *.pdf; do
  if pdfinfo "$f" > /dev/null; then
    : Nothing
    echo "$f" is broken
share|improve this answer
I would suggest to replace pdfinfo with pdftotext. This way all text on every page will be checked. And the > gt character should be &> so that all the error messages don't show up. – schoetbi Oct 17 '14 at 19:29

This is my script

find . -iname '*.pdf' | while read -r f
    if pdftotext "$f" &> /dev/null; then 
        echo "$f" was ok;   
        mv "$f" "$f.broken";
        echo "$f" is broken;   
share|improve this answer

I got myself an answer:

for x in *.pdf; do echo "$x"; pdfinfo "$x" | grep Pages; done

PDFs with errors will show errors.

share|improve this answer
It is a bad idea (and never really needed) to iterate over the output of ls: – slhck Apr 10 '13 at 14:06
@slhck: This should be handled with find (1). :-) – Martin Schröder Apr 11 '13 at 13:15

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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