How to Print files in Linux Using Command Line

How to Print files in Linux Using Command Line


Printing a file is one of the basic functionalities provide by the linux operating system, rather than just printing a file its provides us with a variety of options like to reformat it to adjust the margins, highlight some words, change text orientation and more. Undoubtedly we can print a file directly without passing any extra parameters but that would lead to a less appealing print, so here we see how to print a file and add optional parameters to make it look even better.

How to Print using pr command?

pr command is used as a basic command to print files, it has following syntax –

pr <option(s)> <filename(s)>

pr command does minor formatting to the input file you want to print by supplying options into the pr command, also pr command displays the file to user before printing it.

Here are the other options you can provide along with the pr command –

pr command optionsUsage
-kgives output in k columns
-tremoves header and top/bottom margins from print
-dadds double spaces between the outputs
-htakes item to next header

Printing file where k=2, to print the output in 2 columns –

How to Print using lp/lpr command?

Unlike pr command, lp/lpr can be directly used to print out onto the printer without displaying the file on user’s terminal. Once you are ready with formatting using the pr command, you can use any of these commands to print your file on the printer connected to your computer.

To use lp command make sure you set the default printer, the lp command shows an ID that you can use to cancel the print job or check its status.

  • If you are using the lp command, you can use the -nNum option to print Num numberof copies. Along with the command lpr, you can use -Num for the same.
  • If there are multiple printers connected with the shared network, then you can choose a printer using -dprinter option along with lp command and for the same purpose you can use -Pprinter option along with lpr command. Here printer is the printer name.

Check and Abort file printing using lpstat and cancel command

lpstat command can be used to get a view of the printer’s queue, they may include – request IDs, owners, file sizes, when the jobs were sent for printing, and the status of the requests. We can use lpstat -o to see all output requests

The cancel command terminates a printing request from the lp command. The lprm command terminates all lpr requests. You can specify either the ID of the request (displayed by lp or lpq) or the name of the printer, to cancel whatever request is currently printing, regardless of its ID, simply enter cancel and the printer name –

Along with following commands there are even more commands like lpq (similar to lpstat) , lprm (command will cancel the active printing job if it belongs to you), etc.

Previous How to Know Which WIFI Command Failed on WICED at Boot Time
Next What Is PPA And How To Add Or Remove It In Ubuntu Using Command Line?

About author

You might also like

Linux Topics 0 Comments

Some Important Commands Used In Linux/Unix

This post was last updated on August 3rd, 2020 at 02:51 pmCommand-line interface(CLI) is a way that allows users to interact with computer programs through commands. A user issues commands

Linux Topics 0 Comments

How to install FileZilla in Ubuntu 20.04 LTS ?

Filezilla is a free, opensource, and cross-platform FTP application. This application is based on the client-server model. You can visit Filezilla’s website to download the client and server binaries. The

Linux Topics 0 Comments

How To Create A Zip File In Linux?

This post was last updated on August 1st, 2020 at 12:29 pmZip is an archive file format that supports lossless data compression. Zipping and unzipping tools are available for various


No Comments Yet!

You can be first to comment this post!

Leave a Reply