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 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
up vote 12 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
All my PDFs are flagged as broken. Hundreds of gigabytes of them. Including ones I just created. Whether using pdfinfo or pdftotext... – PatrickT Mar 11 at 7:20

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
To clarify: This script renames the pdf files that are diagnosed as 'broken' by appending .broken to the .pdf extension. – PatrickT Mar 11 at 7:07

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

You must log in to answer this question.

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