Command-line Printing (lp vs lpr)

A 5 star hangout for overworked and underpaid system admins.
Post Reply
User avatar
teancum144
Posts: 136
Joined: 2009/08/19 22:33:34
Location: Pacific Northwest, USA

Command-line Printing (lp vs lpr)

Post by teancum144 » 2010/11/18 02:04:34

As I understand it, there are two different command syntaxes for command-line printing, as follows:

BSD/LPD (Free BSD, Open BSD, Net BSD, Original Sun OS, Mac OS X)
lpr (print)
lpq (display queue)
lprm (remove jobs)

System V (Solaris, SCO, HP-UX)
lp (print)
lpstat (display queue)
cancel (remove jobs)

Both work in CentOS and Linux in general. Both are recognized and supported by CUPS.

Of the two syntaxes, which is considered the Linux standard?

User avatar
AlanBartlett
Forum Moderator
Posts: 9345
Joined: 2007/10/22 11:30:09
Location: ~/Earth/UK/England/Suffolk
Contact:

Re: Command-line Printing (lp vs lpr)

Post by AlanBartlett » 2010/11/18 02:35:25

I can't give you an answer as to which is considered to be a [i]Linux[/i] based OS standard.

However, I can say that in the Unix world the [i]lpr[/i] command family was the earlier standard and the [i]lp[/i] family came later.

Essentially, [i]lpr[/i] (& co) were present up to (and including) AT&T's Unix System III only to be replaced by [i]lp[/i] (& co) in AT&T's Unix System V onwards. ;-)

pjwelsh
Posts: 2632
Joined: 2007/01/07 02:18:02
Location: Central IL USA

Command-line Printing (lp vs lpr)

Post by pjwelsh » 2010/11/18 13:36:08

For CentOS, they are part of the same package called "cups":
[quote]rpm -qf `which lpr`
cups-1.3.7-18.el5_5.8
[/quote]
and
[quote]rpm -qf `which lp`
cups-1.3.7-18.el5_5.8
[/quote]

User avatar
teancum144
Posts: 136
Joined: 2009/08/19 22:33:34
Location: Pacific Northwest, USA

Re: Command-line Printing (lp vs lpr)

Post by teancum144 » 2010/11/24 00:17:45

After looking into this a little further, it seems Linux/CUPS uses a bit more of its printing from System V than it does from BSD. For example, the lpadmin command comes from System V and the only BSD equivalent -- the /etc/printcap file was dropped. Also, the BSD command lpc is has limited functionality in Linux.

That being said, I like some of the BSD style commands better than the System V equivalent, as follows:

The BSD lpq command without any arguments displays both default printer information and the print queue for the default printer:
[code]# lpq
unit9999 is ready
no entries[/code]
To get this same information, two System V commands are needed:
[code]# lpstat -d
system default destination: unit9999

# lpstat -o unit9999
#
[/code]
Note that lpstat produces no print queue output if no jobs are queued. Conversely, the lpq command provides the more explicit "no entries" message if no jobs are queued.

Similarly, the lprm command without any arguments cancels the current print job on the default prnter:

[code]# lprm
lprm: No active jobs on unit9999!
#[/code]
Again, note the explicit feedback even though no jobs were queued.

This time, three System V commands are needed to accomplish the same task:
[code]# lpstat -d
system default destination: unit9999

# lpstat -o unit9999
unit9999-16 root 143360 Tue 23 Nov 2010 03:41:50 PM PST

# cancel 16
#[/code]
Because the preceeding cancel command produces no explicit output, a fourth command is needed to verify the job was cancelled:
[code]# lpstat -o unit9999
#[/code]
Or for more explicit feedback:[code]# lpq
unit9999 is ready
no entries[/code]
From my testing, if the "cancel" command is executed with no arguments accomplishes nothing (but gives no error message or other feedback).

Some System V commands are unique and very useful such as the powerful lpadmin command. Additionally, the lpstat command has useful options with no BSD equivalent. For example,

lpstat -v (displays all configured printers and the devices they are attached to)
[code]# lpstat -v
device for unit9890: ipp://10.10.52.225/ipp
device for unit9999: ipp://10.10.20.199/ipp/printers/unit9999
#[/code]
lpstat -p (displays all configured printers and whether or not they are enabled for printing)
[code]# lpstat -p
printer unit9890 is idle. enabled since Fri 19 Nov 2010 04:07:11 PM PST
none-report
printer unit9999 is idle. enabled since Tue 23 Nov 2010 03:41:59 PM PST
Connected to 10.10.20.199...
#[/code]
lpstat -a (displays all configured printers and whether or not they are accepting requests for additional print jobs.
[code]# lpstat -a
unit9890 accepting requests since Fri 19 Nov 2010 04:07:11 PM PST
unit9999 accepting requests since Tue 23 Nov 2010 03:41:59 PM PST
#[/code]
lpstat -t (displays all configured printers and all status information for each printer)
[code]# lpstat -t
scheduler is running
system default destination: unit9999
device for unit9890: ipp://10.10.52.225/ipp
device for unit9999: ipp://10.10.20.199/ipp/printers/unit9999
unit9890 accepting requests since Fri 19 Nov 2010 04:07:11 PM PST
unit9999 accepting requests since Tue 23 Nov 2010 03:41:59 PM PST
printer unit9890 is idle. enabled since Fri 19 Nov 2010 04:07:11 PM PST
none-report
printer unit9999 is idle. enabled since Tue 23 Nov 2010 03:41:59 PM PST
Connected to 10.10.20.199...
#[/code]

Hopefully, some will find this information useful. :-)

Post Reply