Use the lpadmin command.


Example

Setup network printer named BA_P3 @ 10.20.41.58 port 9100


[cima@opt02 ~] lpadmin -p BA_P3 -E -v socket://10.20.41.58:9100


Config options:

-p <printer_name>    Configures the named printer or class

-E Enables the destination and accepts jobs; this is the same as running the cupsaccept(8) and cupsenable(8) programs on the destination.

-v "device-uri"    Sets the device-uri attribute of the printer queue. Use the -v option with the lpinfo(8) command to get a list of supported device URIs and schemes.

 -m model    Sets a standard System V interface script or PPD file for the printer from the model directory or using one of the driver interfaces. Use the -m option with the lpinfo(8) command to get a list of supported  models.



The config will be appended to the following file /etc/cups/printers.conf

<Printer BA_P3>
UUID urn:uuid:7e445be7-366f-3afe-7c0a-00c4612e6ae4
Info BA_P3
DeviceURI socket://10.20.41.58:9100
State Idle
StateTime 1504084997
Type 4
Accepting Yes
Shared Yes
JobSheets none none
QuotaPeriod 0
PageLimit 0
KLimit 0
OpPolicy default
ErrorPolicy stop-printer
</Printer>



Other useful commands


Display all print jobs

[cima@opt02 ~]$ lpstat -o
BK_P3-1017008           unknown           4096   Thu 28 May 2020 12:55:59 PM MYT


Display all printer status

[cima@opt02 ~]$ lpc status all
BA_P1:
        printer is on device 'socket' speed -1
        queuing is enabled
        printing is enabled
        no entries
        daemon present
BA_P2:
        printer is on device 'socket' speed -1
        queuing is enabled
        printing is enabled
        no entries
        daemon present


Display printer queue status

[cima@opt02 ~]$ lpq -a
Rank    Owner   Job     File(s)                         Total Size
active  unknown 1014041 unknown                         4096 bytes
1st     unknown 1014042 unknown                         4096 bytes
2nd     unknown 1014045 unknown                         4096 bytes


Cancel print job

[cima@opt02 ~]$ sudo cancel BK_P3-1017008