lpr: Print file from command line

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:

In Debian/Ubuntu:

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.

Open it up and Click on Add.adding printer in Linux

Select your printer and add it properly.

lpr command:

Simply type the following command to print simple text file:

lpr filename

List Network Printers:

To get the list of available network printers type:

lpstat -a

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


lpr -Pprinter_name

are same.

Status Check:

Check on the status of specific printer queue using lpq.

lpq -Pprinter_name

Remove queue:

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:

lprm -

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
Posted in Debian, Linux, Linux Command, Ubuntu | Tagged , , , | Leave a comment

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>