Printing from the Linux Command Line

Last updated: Oct 31, 2007

So you have your printer set up with CUPS and you can now print. Ever want to print from the command line? Ever need your bash script to print out system status reports or simply want to print out entire directory of pdfs all in one shot without having to open each pdf individually? Than this quick tip is for you.

After you can successfully print and have your default printer setup in Linux. Open up the terminal. The command to print in Linux is ‘lpr’.

From here you can use the command just like you would any other Linux command. For example if you wanted to print out all pdf’s in a directory you would simply use the following command.

lpr *.pdf

I am sure you can find all kinds of ways to use this. Even ways to torment your co-workers by setting up a cron job lpr print that will print random sayings with ‘fortune’.

#!/bin/bash COUNTER=0 while [ $COUNTER -lt 10 ]; do sleep 10m fortune | lpr let COUNTER=COUNTER+1 done

To use this script open your favorite text editor and create a file with any name you want

vim randomFortunePrint

Then paste the code and save the file.

:wq

Then make the file executable by changing the permissions on your file to 755.

chmod 755 randomFortunePrint

Run your program with:

sh randomFortunePrint

Here is what mine said.

Q: Why did the astrophysicist order three hamburgers? A: Because he was hungry.

I am sure you can find more constructive ways to use this. :) Please let me know what kinds of things you guys come up with.

Need to print shipping labels on your site?

Checkout my product RocketShipIt for simple easy-to-use developer tools for UPS™ FedEx™ USPS™ and more.

Get notified on new posts or other things I'm working on

Share: