CUPS is the current printing system in Linux which provides a server and clients. The lp and lpr are two common commands to print files where lpr is the BSD one, and lp the System V one.
The name 'lp' stands for 'line printer'. By default normal users are allowed to have direct access to the printer. Users have to spool a job in a print queue (lpq to see what print jobs are in the queue). Spooling ensures the orderly printing of jobs.
lp command comes very useful in printing files when GUI is not installed on Linux.
Lp command to Change paper size
It is very easy to change paper size in GUI environment. But how do you change paper size with command prompt?
The lp command prints to A4 paper size by default. However, if you want to print in a different paper size using the command prompt such as A3 or A5 then type as given below. Supported printer sizes are: "a4", "letter", and "legal".
$ lp -o media=A3 /path
Where, -o media=size : Sets the page size to size.
Print a double-sided legal document to a printer called "printer1":
$ lp -d printer1 -o media=legal -o sides=two-sided-long-edge /path
Print an image using a printer called "printer2":
$ lp -d printer2 -o scaling=200 filename
lp command examples
The command given below prints /etc/passwd file to the default printer destination:
$ lp /etc/passwd
Print the “.profile” file to the printer named “Sales”. The -d option specifies the destination.
$ lp -dSales .profile
Simultaneous printing of more than one files:
$ lp -dSales file1 file2 file3
This command places the print request Sales-101 on hold:
$ lp -i Sales-101 -H hold
This command resumes the print request Sales-101:
$ lp -i Sales-101 -H resume
The command given below resumes the print request Sales-101 starting with page 4:
$ lp -i Sales-101 -H resume -P 4-
Use of pipeline with lp command. The command given below will print the output of the “ps -ef” command to the default printer:
$ ps -ef | lp
To display the names of the printers that are connected to your system, use the lpc status command:
$ lpc status Office-ES600: printer is on device 'parallel' speed -1 queuing is enabled printing is enabled no entries daemon present
Conclusion
In this article we learned different options lp command which useful for printing in Linux. Hope you enjoyed reading and please leave your suggestion in the below comment section.