![](/uploads/1/2/5/4/125487296/751272258.jpeg)
This article will guide you through the process of using your CUPS printer by issuing commands in the terminal and also outlines the available print job options you can set in order to fine tune the final prints. 5 responses on “ Using a CUPS printer from command line ”. Things to avoid when using the installation wizard of MediaWiki.
CUPS stands for Common UNIX Printing System.
lpadmin is a command line tool used to configure printer and class queues provided by CUPS.
A system running CUPS is a host that can accept print jobs from client computers, process them, and send them to the appropriate printer. It can also be used to set the server default printer or class.
This tutorial explains how to add a new printer, setup printer options, and manage printers on Linux environment using lpadmin command examples.
1. Adding a New Printer
To add a new network printer with the name “HPLaserJetP3015” use the lpadmin command with -p option as shown below:
To verify if the printer is configured currently, you can use the command as shown in the below example:
2. PPD and Log Files
In the above example, PPD files (is also known as PostScript Printer Description) are created by vendors to describe the entire set of features and capabilities available for their PostScript printers and they are usually located under /usr/share/cups/model/ directory.
If you have any problems with configuring the printer, then please verify the logs at the below location for any error messages. This location may change depending upon the different distribution of Linux.
3. Configure Printer on Parallel Port
In order to configure the printer on the parallel port (/dev/lp0), use the lpadmin command as shown in this example:
4. View All Available Ports for Printer Setup
Also to list all the available ports or interfaces available to configure the printer can be displayed using lpinfo command,
5. Multiple Printer Classes
CUPS always checks for an available printer in the order in which printers were added to a class.
You can add 1 or more printers to a class and when one of the printers becomes unavailable, the other printer defined in the class handles the print job requests.
It is not mandatory to add printers in classes. One printer class can themselves be members of other classes so it is possible for you to define printer classes for high availability for printing.
Once you configure the printer class, you can print to the printer class in the same way that you point to a single printer.
For example, If you have 2 Laserjet printers and 2 deskjet printers. you can create a class known as “Class-Laserjet”consisting 2 Laserjet Printers, and create another class known as “Class-Deskjet” printers and then create another class containing these 2 classes.
This way even if both the laserjet or deskjet printers go down, the other class serves the printing jobs.
6. Add Printer to a Class
To add a printer to the class, use the below command.
To verify whether the printers are in printer class:
7. Remove Printer from a Class
To remove a printer from the class you can use the lpadmin command as shown in the below example:
in this example, myclass has two printers:
Remove the HPDESKJET882 printer from myclass as shown below:
Once you remove it, you’ll see only the HP Laser Jet Printer:
8. Remove a Whole Printer Class
Using the -x option, you can remove the class. as shown below.
Please note that the printer configuration still exists even if you removed the class.
9. Change Printing Option
To change the printing options for the printer, you can execute the below commands.
List all the available options for the printer using lpoptions command as shown below.
In this example, you will see all the activated options is prefixed with asterisk symbol. If there is no asterisk is present, then it uses default settings.
10. Change Printer Resolution
To change the resolution of the printer to 300x300dpi, you can use the lpadmin command as shown below:
Here are the other options you can set for any printer using lpadmin with –o option as described in above example,
- job-k-limit=value – Sets the kilobyte limit for per-user quotas. The value is an integer number of kilobytes.
- job-page-limit=value – Sets the page limit for per-user quotas. The value is the integer number of pages that can be printed; double-sided pages are counted as two pages.
- job-quota-period=value – Sets the accounting period for per-user quotas. The value is an integer number of seconds.
- job-sheets-default=banner – Sets the default banner pages to use for print jobs.
- name=value – Sets a PPD option for the printer. PPD options can be listed using the -l option with the lpoptions(1) command.
- name-default=value – Sets a default server-side option for the printer.
- port-monitor=name – The specified port monitor must be listed in the printer’s PPD file.
- printer-error-policy=name – Sets the error policy to be used when the printer backend is unable to send the job to the printer.
- printer-is-shared=true/false – Sets the printer to shared/published or unshared/unpublished.
- printer-op-policy=name – Sets the IPP operation policy associated with the printer. The name must be defined in the cupsd.conf in a Policy section. The default operation policy is “default”.
11. Remove Printer from Configuration File
To remove a CUPS printer from the printer configuration file, you can use the -x option as shown below:
12. Allow/Deny User or Groups to Configure Printer Options
You can allow the individual users or group to configure the printer options using lpadmin commands.
The following command will allow the user karthik to configure the printer option on HPLaserJetP3015 printer:
You can also block the user from changing the settings/options or configure printer using the below command.
The following command will deny the user karthik to configure the printer option on HPLaserJetP3015 printer:
If there is a group that needs to be allowed access, you can use the group name preceding with @ symbol. Multiple user names or groups can be given separated by commas.
For example, the following will allow users from sysadmin group to configure printer options.
The following will deny users from developer group to configure printer options.
> Add your comment
If you enjoyed this article, you might also like..
CUPS provides both the System V (lp(1)) and Berkeley (lpr(1)) printing commands for printingfiles. In addition, it supported a large number of standard andprinter-specific options that allow you to control how and wherefiles are printed.
Printing Files
![Cups Install Printer Command Line Cups Install Printer Command Line](/uploads/1/2/5/4/125487296/219390759.png)
CUPS understands many different types of files directly,including text, PostScript, PDF, and image files. This allows youto print from inside your applications or at the command-line,whichever is most convenient! Type either of the followingcommands to print a file to the default (or only) printer on thesystem:
Choosing a Printer
Many systems will have more than one printer available to theuser. These printers can be attached to the local system via aparallel, serial, or USB port, or available over the network. Usethe lpstat(1) command to see a listof available printers:
The
-p
option specifies that you want to see alist of printers, and the -d
option reports thecurrent default printer or class.Use the
-d
option with the lp command toprint to a specific printer:or the
-P
option with the lpr command:Setting the Default Printer
If you normally use a particular printer, you can tell CUPS touse it by default using the lpoptions(1) command:
Printing the Output of a Program
Both the lp and lpr commands support printingfrom the standard input:
If the program does not provide any output, then nothing willbe queued for printing.
Specifying Printer Options
For many types of files, the default printer options may besufficient for your needs. However, there may be times when youneed to change the options for a particular file you areprinting.
The lp and lpr commands allow you to passprinter options using the
-o
option:The available printer options vary depending on the printer.The standard options are described in the 'Standard Printing Options' sectionbelow. Printer-specific options are also available and can belisted using the lpoptions command:
Creating Saved Options
Saved options are supported in CUPS through printerinstances. Printer instances are, as their name implies, copiesof a printer that have certain options associated with them. Use thelpoptions command to create a printer instance:
The
-p printer/instance
option provides the name ofthe instance, which is always the printer name, a slash, and theinstance name which can contain any printable characters exceptspace and slash. The remaining options are then associated with theinstance instead of the main queue. For example, the followingcommand creates a duplex instance of the LaserJet queue:Instances do not inherit lpoptions from the mainqueue.
Printing Multiple Copies
Both the lp and lpr commands have options forprinting more than one copy of a file:
Copies are normally not collated for you. Use the
-o collate=true
option to get collated copies:Canceling a Print Job
The cancel(1) and lprm(1) commands cancel a print job:
The job-id is the number that was reported to you bythe lp command. You can also get the job ID using the lpq(1) or lpstat commands:
Moving a Print Job
![Cups Install Printer Command Line Cups Install Printer Command Line](/uploads/1/2/5/4/125487296/897999984.jpg)
The lpmove(8) command moves a printjob to a new printer or class:
The job-id is the number that was reported to you bythe lp or lpstat commands. Destination is thename of a printer or class that you want to actually print the job.
Note:The lpmove command is located in the system commanddirectory (typically /usr/sbin or /usr/local/sbin),and so may not be in your command path. Specify the full path to thecommand if you get a 'command not found' error, for example:
Standard Printing Options
The following options apply when printing all types offiles.
Selecting the Media Size, Type, and Source
The
-o media=xyz
option sets the media size,type, and/or source:The available media sizes, types, and sources depend on theprinter, but most support the following options (case is notsignificant):
Letter
- US Letter (8.5x11 inches, or 216x279mm)Legal
- US Legal (8.5x14 inches, or 216x356mm)A4
- ISO A4 (8.27x11.69 inches, or 210x297mm)COM10
- US #10 Envelope (9.5x4.125 inches, or 241x105mm)DL
- ISO DL Envelope (8.66x4.33 inches, or 220x110mm)Transparency
- Transparency media type or sourceUpper
- Upper paper trayLower
- Lower paper trayMultiPurpose
- Multi-purpose paper trayLargeCapacity
- Large capacity paper tray
The actual options supported are defined in the printer's PPDfile in the
PageSize
, InputSlot
, andMediaType
options. You can list them using thelpoptions(1) command:When
Custom
is listed for the PageSize
option, you can specify custom media sizes using one of the following forms:where 'WIDTH' and 'LENGTH' are the width and length of the media in points, inches, centimeters, or millimeters, respectively.
Setting the Orientation
The
-o landscape
option will rotate the page 90degrees to print in landscape orientation:The
-o orientation-requested=N
option rotates thepage depending on the value of N:-o orientation-requested=3
- portrait orientation (no rotation)-o orientation-requested=4
- landscape orientation (90 degrees)-o orientation-requested=5
- reverse landscape or seascape orientation (270 degrees)-o orientation-requested=6
- reverse portrait or upside-down orientation (180 degrees)
Printing On Both Sides of the Paper
The
-o sides=two-sided-short-edge
and -osides=two-sided-long-edge
options will enable two-sidedprinting on the printer if the printer supports it. The -osides=two-sided-short-edge
option is suitable forlandscape pages, while the -osides=two-sided-long-edge
option is suitable for portraitpages:The default is to print single-sided:
Selecting the Banner Page(s)
The
-o job-sheets=start,end
option sets the bannerpage(s) to use for a job:If only one banner file is specified, it will be printedbefore the files in the job. If a second banner file isspecified, it is printed after the files in the job.
The available banner pages depend on the local systemconfiguration; CUPS includes the following banner files:
none
- Do not produce a banner page.classified
- A banner page with a 'classified' label at the top and bottom.confidential
- A banner page with a 'confidential' label at the top and bottom.secret
- A banner page with a 'secret' label at the top and bottom.standard
- A banner page with no label at the top and bottom.topsecret
- A banner page with a 'top secret' label at the top and bottom.unclassified
- A banner page with an 'unclassified' label at the top and bottom.
Holding Jobs for Later Printing
The
-o job-hold-until=when
option tells CUPS todelay printing until the 'when' time, which can be one of thefollowing:-o job-hold-until=indefinite
; print only after released by the user or an administrator-o job-hold-until=day-time
; print from 6am to 6pm local time-o job-hold-until=night
; print from 6pm to 6am local time-o job-hold-until=second-shift
; print from 4pm to 12am local time-o job-hold-until=third-shift
; print from 12am to 8am local time-o job-hold-until=weekend
; print on Saturday or Sunday-o job-hold-until=HH:MM
; print at the specified UTC time
Releasing Held Jobs
Aside from the web interface, you can use the lp commandto release a held job:
where 'job-id' is the job ID reported by the lpstatcommand.
Setting the Job Priority
The
-o job-priority=NNN
option tells CUPS toassign a priority to your job from 1 (lowest) to 100 (highest),which influences where the job appears in the print queue. Higherpriority jobs are printed before lower priority jobs, howeversubmitting a new job with a high priority will not interrupt analready printing job.Specifying the Output Order
The
-o outputorder=normal
and -o outputorder=reverse
options specify the order of the pages. Normal order prints page 1 first, page 2 second, and so forth. Reverse order prints page 1 last.Selecting a Range of Pages
The
-o page-ranges=pages
option selects a rangeof pages for printing:As shown above, the
pages
value can be a single page, arange of pages, or a collection of page numbers and ranges separated bycommas. The pages will always be printed in ascending order, regardlessof the order of the pages in the page-ranges
option.The default is to print all pages.
Note:The page numbers used by
page-ranges
refer to the outputpages and not the document's page numbers. Options like number-up
can make the output page numbering not match the document page numbers.N-Up Printing
The
-o number-up=value
option selects N-Upprinting. N-Up printing places multiple document pages on asingle printed page. CUPS supports 1, 2, 4, 6, 9, and 16-Upformats; the default format is 1-Up:The
-o page-border=value
option chooses theborder to draw around each page:-o page-border=double
; draw two hairline borders around each page-o page-border=double-thick
; draw two 1pt borders around each page-o page-border=none
; do not draw a border (default)-o page-border=single
; draw one hairline border around each page-o page-border=single-thick
; draw one 1pt border around each page
The
-o number-up-layout=value
option chooses thelayout of the pages on each output page:-o number-up-layout=btlr
; Bottom to top, left to right-o number-up-layout=btrl
; Bottom to top, right to left-o number-up-layout=lrbt
; Left to right, bottom to top-o number-up-layout=lrtb
; Left to right, top to bottom (default)-o number-up-layout=rlbt
; Right to left, bottom to top-o number-up-layout=rltb
; Right to left, top to bottom-o number-up-layout=tblr
; Top to bottom, left to right-o number-up-layout=tbrl
; Top to bottom, right to left
Scaling to Fit
The
-o fit-to-page
option specifies that the documentshould be scaled to fit on the page:The default is to use the size specified in the file.
Note:This feature depends upon an accurate size inthe print file. If no size is given in the file, the page may bescaled incorrectly!
Printing in Reverse Order
The
-o outputorder=reverse
option will print thepages in reverse order:Similarly, the
-o outputorder=normal
option willprint starting with page 1:The default is
-o outputorder=normal
forprinters that print face down and -o outputorder=reverse
for printers that print face up.Printing Mirrored Pages
The
-o mirror
option flips each page along thevertical axis to produce a mirrored image:This is typically used when printing on T-shirt transfermedia or sometimes on transparencies.
![](/uploads/1/2/5/4/125487296/751272258.jpeg)