Printing Command To Be Used

Printing : Commands covered in this section:   lpr, lpq, lprm, enscript 

At the time that UNIX was being developed, line printers were all the rage. This is reflected in the simple printing system used in UNIX. This system consists of a print server (called lpd on many systems), which sends jobs placed in the print queue to the printer, and several client programs that allow you to place jobs in the print queue (lpr), check the status of the print queue (lpq), and remove jobs from the print queue (lprm). 

Exercise 1.1 

Use the lpr command to send a simple text file to the printer. 
          % lpr /etc/hosts 

If no printer is specified, lpr will send the print job to the default printer. To specify an alternate printer, use the "-P" option. 

Exercise 1.2 

Use lpr -P to print to a specific printer. 
          % lpr -Pmyprinter /etc/hosts

Since UNIX is a multi-user system, there's a chance that several users will be sending jobs to the printer simultaneously. To check on the status of your print job, you can use lpq. 

Exercise 1.3 

Check on the status of the "myprinter" print queue using lpq. 
          % lpq -Pmyprinter

          Rank  Owner      Job   Files                  Total Size
          active root           3     nsswitch.conf           958 bytes
          1st     dopey        4     (standard input)       1387 bytes
          2nd    sneezy       5     myfile                    5623 bytes
          3rd     sneezy      6     myfile2                   5692 bytes
          4rd     grumpy     7     hosts                      2317 bytes 

The display returned by lpq is a table, showing the rank of each pending job, the user who owns the job, the job id, the name of each file, and the size. If you omit the "-P" option, lpq will show the status of the default print queue. 

To remove a print job from the queue, use the lprm command. You can remove a particular job by specifying its job id. 

Exercise 1.4 

Remove a pending job from the "myprinter" print queue using lprm. 
          % lprm -Pmyprinter 6
          myprinter-6 dequeued

In this case, the user sneezy is removing job number 6 (myfile2) from the queue. 

As with lpr and lpq, omitting the "-P" flag causes lprm to perform the requested operation on the default print queue. 

The lpr command usually just copies the specified file into the print queue unmodified, whether it's a simple text file or a PostScript file (PostScript is a page description language developed by Adobe). In some cases, you may want to modify a text file (adding margins, a header, etc.). One command that allows you to do this is enscript (this program was created by Adobe; there are two free clones: genscript and nenscript). These programs are not part of most standard UNIX distributions, but they are often installed by the system administrator. 

enscript has many options, but a few of the useful ones include "-G" (add a "gaudy" header, including current date/time, file name, and page number), "-r" (rotate the page orientation to landscape), and "-2" (print two columns instead of one). In order to make these changes to a text file, enscript converts it to PostScript. 

Exercise 1.5 

Print a text file using enscript with the options specified above. 

          % enscript -2Gr -Pmyprinter /etc/hosts 

Have a Unix Problem
Unix Forum - Do you have a UNIX Question?

Unix Books :-
UNIX Programming, Certification, System Administration, Performance Tuning Reference Books

Return to : - Unix System Administration Hints and Tips

(c) www.gotothings.com All material on this site is Copyright.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
All product names are trademarks of their respective companies.
The site www.gotothings.com is in no way affiliated with or endorsed by any company listed at this site.
Any unauthorised copying or mirroring is prohibited.