Javatpoint Logo
Javatpoint Logo

Linux Print

In Linux, different commands are used to print a file or output. Printing from a Linux terminal is a straightforward process. The lp and lpr commands are used to print from the terminal. And, the lpg command is used to display queued print jobs.

Printing the double-sided document or in portrait mode is a bit complicated process. And there may be many other operations that we want to perform, such as printing multiple copies or canceling a print job, which can be difficult to perform.

Linux lp and lpr command

CUPS (Common Unix Printing System) provides the system commands for printing files. Additionally, it supports several standard options to control the print operation. Let's see how to print files.

How to print files in Linux

To print files from Linux terminal, execute the lp and lpr command. It will print the file from the default printer. Execute it as follows:

The above commands will print the specified file.

Choosing a Printer

If our system has connected with more than one printer, you can choose one of them to print the particular file. These printers can be connected with different methods such as parallel, serial, USB port, networking.

To display a list of the connected printers, execute the command as follows:

The above command will display a list of available printers. The '-p' option is used to display a list of the printers, and the '=d' option specifies the default printer.

To print a file with a specific printer, execute the lp command with the '-d' option or lpr command with the '-P' option. Consider the following commands:

In the above commands, both commands will perform the same operation.

For example, to print a file 'Notes.pdf' by the printer name 'HPM375', execute the command as follows:

Setting the Default Printer

We can set a particular printer as a default printer from the connected printers. To set a printer as the default printer, execute the lpoptions command with the '-d' option as follows:

Printing Multiple Copies

The lp and lpr both commands support to print multiple copies of a file. To specify the number of copies, use the '-n' option with lp command as follows:

Use the '-#' option with lpr command for the same task as follows:

Generally, the printed copies are not collated. To collate the copies, use the "-o collate=true" option. Consider the following commands:

Canceling a Print Task

We can cancel a print task by using the cancel and lprm commands. To cancel a queued job, execute the commands as follows:

The Job-id can be seen by executing the following commands:

lpq

lpstat

Moving a Print Task

We can forward a queued job to a different printer by using the lpmove command. To move a print task to a new printer or class, execute the command as follows:

The job-id is the process id of the task that can be seen by lp or lpstat commands. The destination is the printer, to which we want to forward the print task.

The most common error that can be seen during the move operation is "command not found" error. Since, the lpmove command is located in the system command directory, and may not be in our current path. To overcome this problem, specify the full to the path.

Create a printer Instance

We can create saved options by creating an instance of the printer, such as their name implies, the number of copied with certain options. To create a printer instance, use the lpoptions command as follows:

In the above command, the -p printer/instance option specifies the name of the instance. These instances can be a printer name, a slash, and any instance name.

Setting the Orientation

We can set the orientation of the page by using the '-o' option. To rotate the page at 90-degrees in landscape mode, execute the following commands:

The "-o orientation-requested=N" option is used to rotate the page according to the value of N. Some standard values are as follows:

  • -o orientation-requested=3: It is used for the portrait orientation (no rotation)
  • -o orientation-requested=4: It is used for the landscape orientation (90 degrees)
  • -o orientation-requested=5: It is used for the reverse landscape or seascape orientation (270 degrees)
  • -o orientation-requested=6: It is used for the reverse portrait or upside-down orientation (180 degrees).

Selecting the Media Size, Type and Source

To set the media size, type, and source, use the "-o media=xyz" option. Some common media customization examples are as follows:

The media options are completely dependent on the type of printer. But some standard printers support the following options:

  • Letter: It is used for the US Letter (8.5x11 inches, or 216x279mm).
  • Legal: It is used for the US Legal (8.5x14 inches, or 216x356mm).
  • A4: It is used for ISO A4 (8.27x11.69 inches, or 210x297mm).
  • COM10: It is used for US #10 Envelope (9.5x4.125 inches, or 241x105mm).
  • DL: It is used for ISO DL Envelope (8.66x4.33 inches, or 220x110mm).
  • Transparency: It is used for transparency media type or source.
  • Upper: It is used to specify the upper paper tray.
  • Lower: It is used to specify the lower paper tray.
  • MultiPurpose: It is used to specify a multi-purpose paper tray.
  • LargeCapacity: It is used to specify a large capacity paper tray.

The printer's PPD file has a description of all supported options. To list them, execute the following command:

We can customize the page size by using the 'Custom' option. We can specify options in the following forms:

We can specify the width and length in the "in, cm, and mm" unit.

Printing on Both Sides of the Paper

To enable two-sided printing, use the "-o sides option" as follows:

The above commands will enable two-sided printing if supported by the printer. The "-short-edge" is used for landscape mode, and the "-long-edge" is used for portrait mode.

Holding and Issuing Print Tasks for Later

The "-o job-hold-until=when" option is used to hold the prints for later until the specified time. To hold a task, execute the command as follows:

The above command will hold the task for the indefinite time. It will print only after released by the user or an administrator. Following are some time parameters that can be used to hold the task:

  • day-time: It is used for the time from 6 am to 6 pm local time.
  • night: It is used for the time from 6 pm to 6 am local time.
  • second-shift: It is used for the time from 4 pm to 12 am local time.
  • third-shift: It is used for the time from 12 am to 8 am local time.
  • weekend: It is used to print on Saturday or Sunday.
  • HH:MM: It is used to print at the specified UTC.

Issuing Held Tasks

To issue a held task, execute the lp command as follows:

The "job-id" can be displayed by using the lpstat command.

Manual for the lp and lpr command

If you face any issue during the use of lp and lpr command, you can take help from the terminal by exploring the manual. The manual will display all the supported options with their brief description. To access the manual, execute the following commands:


Next TopicKill Process Linux




Youtube For Videos Join Our Youtube Channel: Join Now

Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA