Thursday, 6 December 2012

Printing from the Linux command line

To print a file from the Linux command line, use the simple command:
 lpr FILENAME  
It's that easy!

I came across this while trying to print all pdf files in a directory. To do this, the simple bash script you need is:
 #!/bin/bash  
 for file in *.pdf; do  
   /usr/bin/lpr "$file"  
 done  

Save this into a file - I called mine print-all-pdfs.sh. Then make it executable using
 chmod +x print-all-pdfs.sh  

Copy it to the directory you want to run it in, then execute with
 ./print-all-pdfs.sh  

For an additional challenge, can anyone adapt the above script to print all .pdfs from directories recursively? Answers in the comments below!


[References] Bash script adapted from a LinuxForums post.

No comments:

Post a Comment

Please leave a comment if you find this blog helpful or interesting! I'd love to hear from you!