Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I tried this command but I think something is wrong with '{}' '{}'. By the latter, I want InputXYZ.pdf OutputXYZ.pdf (I do not want any dupe files, I want to replace the old files to make reading a bit more convenient).

$ find . -name "*.pdf" -ok qpdf --password=passMe --decrypt '{}' '{}' \;

If you have better and simpler ideas to handle this kind of repetitive pass-typing probs with other programs, do not hesitate to comment or answer. Actually, my teachers use many different passwords and it is quite mess to read the documents. Perhaps, some file with their passwords and then just the find -cmd testing every possibility?

share|improve this question
add comment

2 Answers

You can't make the input file the same as the output file. At best, qpdf will complain and not do anything. At worst it will truncate the output file to zero bytes and then complain that the input file is empty. So use this:

find . -name "*.pdf" -ok qpdf --password=passMe --decrypt '{}' '{}'.decoded.pdf \;

You can go back and remove the dups once you know qpdf didn't trash your files in some unexpected way.

share|improve this answer
add comment

Given @Kyle Jones' answer as decrypt_all_files_with(), you could wrap everything in a for-loop,

for pass in $(cat passwords.txt)
  do decrypt_all_files_with($pass)
done

(but you possibly want to use -exec instead of -ok, as it doesn't ask for confirmation).

share|improve this answer
add comment

Your Answer

 
discard

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