Linux PrintIn 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 commandCUPS (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 LinuxTo 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 PrinterWe 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 CopiesThe 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 TaskWe 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 TaskWe 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 InstanceWe 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 OrientationWe 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:
Selecting the Media Size, Type and SourceTo 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:
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 PaperTo 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 LaterThe "-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:
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 commandIf 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
|