In Linux, The spooling printing method is used. When you need to print a file, the file is not directly sent to the printer, but to the spool directory, A background process responsible for printing then sends the data to the printer.
Linux defines a print buffer for each printer. The printer daemon often scans the print buffer to check whether new files are to be printed. If it exists, print the files in the buffer in the FIFO order.
In addition to printing on a local printer, Linux can also print data remotely through a network printer.
Command Used for Printing
Linux provides a set of printing commands. In general, the print command uses the default printer. If the user defines the printer environment variable, the print command uses the printer defined by this variable. In addition, you can also specify the printer to use on the command line.
LPR command
The LPR command is an offline printing command that stores the print job in the print Buffer Queue. Each printer specified for the Linux system has its own print buffer directory, and the minfree file in each directory specifies the number of disk blocks that store the print files.
LPR communicates with the LPD daemon. lpd scans the/etc/printcap file, queries the cache directory of the printer, controls the printing by LPD, and sends the data to the actual printer. If no file is specified, LPR uses the standard input.
The format of the LPR command is:
LPR [-P printer] [# num] [other options] [name…]
The meanings of the options in the command are as follows:
-P specifies the printer. If this option is not used, use the printer specified by the default printer or environment variable printer.
-Send an email after M is printed.
-# Print num copies.
Lpq command
Lpq is a Buffer Queue check command. It checks print files in the buffer zone through lpd and reports the status of a specified job or all jobs of a specified user. The lpq command without any parameters shows any job in the queue. An important information in the display result of The lpq command is the job ID, which identifies a specific job. To cancel a suspended job, you must specify the ID number in the command.
The format of the lpq command is:
Lpq [-L] [-P printer] [job #] [user…]
The meanings of the options in the command are as follows:
-P specifies a printer; otherwise, use the printer specified by the default printer or environment variable printer.
-L print the information of all the files that constitute the job.
For each submitted job, The lpq report username, the level in the queue, the file that makes up the job, the job ID, and the total size.
Lprm command
The lprm command is used to delete a print job from the Buffer Queue. You can use this command to delete one or more of your print jobs from the buffer queue.
The format of the lprm command is:
Lprm [-P printer] [-] [job #] [user…]
The meanings of the options in the command are as follows:
-P specifies a printer; otherwise, use the printer specified by the default printer or environment variable printer.
-Delete all print jobs of the user.
Delete jobs belonging to user in the user queue (only super users can do this ).
Job # by specifying the job number # deleting a print job, the job number can be obtained through the lpq command, such:
$ Lpq-l
LST: Ken [job #013 ucbarpa]
(Standard input) 100 bytes
$ Lprm 13
Print buffer directory
For printing, there is a very important directory, that is, the print buffer directory. The data to be printed is concentrated here before being printed. A printer usually corresponds to a print buffer Directory, which makes it easier to manage the printer. For example, the system uses/var/spool/lpd as the primary print buffer, and each printer has a directory with the same name under the primary print buffer. Therefore, the printer named ps_nff uses/var/spool/lpd/ps_nff as its print buffer directory.