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 options||Usage|
|-k||gives output in k columns|
|-t||removes header and top/bottom margins from print|
|-d||adds double spaces between the outputs|
|-h||takes 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.
You might also like
If you are looking to copy a directory in Linux using a command line, then here I have explained what command to use to copy a folder in Linux or
I already discussed briefly about Aptitude which is a debian package manager. In this article, we will see it in more detail and also we will discuss how can we
Telnet basically stands for “teletype network”. It is an old network protocol that works on the application layer of the OSI model. It connects to a remote system using the