The lpr (line printer) command prints the file from the Linux terminal. The lpr utility places one or more files in a print queue for printing. The concept of queue allows several users of the system allow to send output to the single printer. The queue are printed simultaneously i.e the first file in the queue gets printed first and so on. If you handle most of your file using command line editors like vim or nano and want some immediate output in hardcopy then you will find lpr command very quick and handy. To print using lpr command the printer must be configured and connected to your system. System printer configuration should be installed, follow the instruction to install:
sudo apt-get install system-config-printer
In Fedora/Cent OS/RedHat:
sudo yum install system-config-printer
In other distros, system-config-printer should be available in repository.
Select your printer and add it properly.
Simply type the following command to print simple text file:
List Network Printers:
To get the list of available network printers type:
Add to the specific printer:
There can be many printer available. Use -P to print to a specific printer.
lpr -Pprinter_name filename
White space after -P doesn’t matter:
lpr -P printer_name
Check on the status of specific printer queue using lpq.
As you can see from the above command, each queue has a unique id. You can remove files from queue using lprm command:
lprm -Pprinter_name 6
To cancel all the print jobs use the following command:
Print all the files in a directory:
This is a very simple trick to print all the files with same extension in a directory. You need to be in that directory. Type the following command to print all hte files stored in a directory:
lpr -o landscape *.txt
That’s it! All the files with .txt extensions are printed in a landscape format. Printer name can be specified in the same command as:
lpr -o landscape -Pprinter_name *.txt