Thursday, 6 December 2012

Printing from the Linux command line

To print a file from the Linux command line, use the simple command:
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:
 for file in *.pdf; do  
   /usr/bin/lpr "$file"  

Save this into a file - I called mine Then make it executable using
 chmod +x  

Copy it to the directory you want to run it in, then execute with

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!