How to batch print multiple PDFs from multiple (sub)folders in linux (command line, find, xargs and lpr)

Use the command line command lpr on Linux to print several files (in this case PDFs) from several folders in the same tree.

Context

I needed to print several PDF files which were in several folders under a main folder. Ex. Folder1/pdf1.pdf, Folder2/Folder3/pdf2.pdf, and so on.

To open each folder and each file to print them was too much time and work, and I didn't find a way to use [Nemo] to print all the files.

I have used find, xargs before, and I found the command lpr allowed me to print from the terminal. (I wrote an article which also uses xargs some time ago here: How to find files using Regex (Regular Expressions) in GNU/Linux and MacOs command line and do something.)

Solution

After searching for some information (see References), I used the following line to search for all the files in all the subfolders and send their paths to lpr using xargs.

This should work if the printer you want to use is set as default. If you want to use a specific printer check the last references, which uses the argument -P "$printer" with lpr to set a printer.

find -iname '*.pdf' | xargs -i lpr {}

This will print all the files found with find in the folder you are in.

References

[Nemo]

file browser in Linux Mint

Comments

Comments powered by Disqus