Take the 2-minute tour ×
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
add comment

2 Answers 2

up vote 4 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
  else
    echo "$f" is broken
  fi
done
share|improve this answer
add comment

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
3  
It is a bad idea (and never really needed) to iterate over the output of ls: mywiki.wooledge.org/ParsingLs –  slhck Apr 10 '13 at 14:06
2  
@slhck: This should be handled with find (1). :-) –  Martin Schröder Apr 11 '13 at 13:15
add comment

Your Answer

 
discard

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.