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.
This will print all the files found with find in the folder you are in.
References
file browser in Linux Mint
- 2024-07-25 (Quick-note) Troubleshooting Dual Monitor Issues on KDE on Ubuntu/ Linux Mint 2 min read.
- 2023-11-16 How to configure an Ubuntu Linux server to allow SSH sessions only with a key and disable password-based 3 min read.
- 2023-05-11 How to auto restart command/ process in Linux after specific run time or duration (quick-note) 1 min read.
- 2022-12-22 How to find all processes with a specific string in their name and kill them all (in linux command line using ps, grep and awk) 1 min read.
- 2022-11-17 How to copy files to remote server through SSH Tunnel using ngrok and rsync (quick-note) 1 min read.
- 2022-11-03 How to download Google Takeout files (150GB+) with wget (on a remote server) 2 min read.
- 2021-06-10 How to import several folders with files into WordPress Media Library using wp-cli 1 min read.
- 2020-06-02 How to manage several SSH Config files on Mac and Linux (quick-note) 1 min read.
- 2019-03-24 How to find files using Regex (Regular Expressions) in GNU/Linux and MacOs command line and do something. 3 min read.
Comments
Comments powered by Disqus