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
- Make xargs handle filenames that contain spaces
- Print Multiple PDF’s or Doc’s without opening Each One???
- Printing a file from the right-click context menu in Nautilus
- lpr man-pages
- xargs man-pages
- find man-pages
[Nemo]
file browser in Linux Mint
- 2022–11–03 15:00 How to download Google Takeout files (150GB+) with wget (on a remote server)
- 2021–06–10 17:54 How to import several folders with files into WordPress Media Library using wp-cli
- 2020–06–02 17:06 How to manage several SSH Config files on Mac and Linux (quick-note)
- 2019–03–24 07:30 How to find files using Regex (Regular Expressions) in GNU/Linux and MacOs command line and do something.