Printing from UNIX systems
Reviewed by Murray Anderegg 02/27/2013
This article describes how to print jobs from the Department’s UNIX computer systems. Additional information on printing, including printing from other operating systems, can be found in the documents listed at the end of this article.
Printer naming conventions
Here is a list of example printer names:
ljsn156 – HP LaserJet printer room SN156
delsn107 – Dell Color printer in room SN107
djsn245 – HP DesignJet plotter in SN245
ljfb131 – HP LaserJet printer in room FB131
That is, there are two or three characters indicating the kind of printer, then two letters indicating the building, and three digits giving the room. Most printers also are available with duplexing, i.e., printing on both sides of the page, enabled by adding a lower-case ‘d’ as a suffix to the printer name, e.g. ljsn266d.
UNIX Printing commands
NOTE: Linux users will probably prefer to use the document viewer to print most types of files under Linux. The GNOME document viewer is named ‘evince’. The document viewer applications have a rich palette of formatting options that can be altered and previewed.
Linux supports both BSD and System V style printing commands. BSD UNIX uses the commands ‘lpr’ to print, ‘lpq’ to list a queue of jobs waiting for a printer and ‘lprm’ to remove a job from a queue. Use the ‘-P’ flag to specify the printer. For example, to print a job on ljsn156d, check the status of the queue, and cancel your job, execute:
lpr -Pljsn156d /etc/ntp.conf
lprm -Pljsn156d <job number>
System V UNIX uses the commands ‘lp’ to print, ‘lpstat’ to list print jobs and ‘cancel’ to remove job from a queue. ‘lp’ uses the ‘-d’ flag to specify the printer destination. ‘lpstat’ and ‘cancel’ specify the printer queue as one of the options. For example, to print a job on ljsn156d, check the status of the queue, and cancel your job, execute:
lp -d ljsn156d <filename>
cancel <id> <ljsn156d>
A rough correlation between BSD and System V print commands is:
lpr – lp
lpq – lpstat
lprm – cancel
Read the manual pages on these commands for specifics.
Changing Your Default Printer
Unless you specify another printer at the time you submit a print job, your printout will print on the default printer. If you wish to change your personal default printer, execute:
in tcsh or csh, setenv PRINTER <printername>
in bash or ksh, export PRINTER=<printername>
Executing the above commands will change your default printer for the current login session. To change it permanently, place these commands in the appropriate rc file for your shell, e.g. .bashrc, .cshrc or .kshrc.
Changing your GNOME environment default printer
From the menus in the GNOME desktop environment, select:
‘System’ -> ‘Administration’ -> ‘Printing’
right-click on the printer and choose ‘Set as Default’.
Printing unformatted ASCII text
The standard UNIX commands to send jobs to printers are: ‘lpr’ and ‘lp’. Without any options, these commands send output to the default printer. To direct your job to another printer, use the appropriate option, e.g. ‘-P<printername>’ for ‘lpr’ or ‘-d <printername>’ for ‘lp’. For example, to print a file to ljsn266d, use either:
lpr -Pljsn266d <filename>
lp -d ljsn266d <filename>
Printing formatted ASCII text
To print formatted ASCII text from a bsd system, use the ‘pr’ command. This will send output to your default printer. The input will be separated into 66-line pages, each with a 5-line header that includes the page number, date, time and the path name of the file and a 5-line trailer consisting of blank lines. For example,
pr <pr-options> <filename> | lpr <lpr-options>
pr <pr-options> <filename> | lp <lp-options>
If you wish to do more advanced formatting on a printer, use the ‘enscript’ command. Some features offered by enscript include the ability to print in landscape (rotated) mode, to specify your font, and to word-wrap text. A common usage of the ‘enscript’ command is the command
enscript -2rG -P<printer> <filename>
This prints your text in landscape (rotated) mode, includes a “fancy” header, word-wraps your text, and prints in two columns. For more details on the enscript command, see the enscript manual page.
Printing PDF and PostScript file
A PDF file can be opened and printed in a document viewer application such as evince. This may be easier than trying to debug manual lpr/lp options.
Printing PDF and PostScript files in the Computer Science department is easy. Postscript files are commonly given names ending in “.ps”, and they are files that begin with the characters “%!”.
PDF files are commonly given names ending in “.pdf”. Although PDF files are binary and contain bytes that won’t display well in a terminal, they may be sent directly to a printer, using the same commands that you would use to print ASCII text:
lpr -P<printername> <filename>
lp -d <printername> <filename>
Please note that you should not attempt to use any ASCII text formatting commands, such as ‘print’ or ‘pr’, with either PDF or PostScript files. For example, to print a file called myfile.txt to ljsn107d
lpr -P ljsn107 myfile.txt
To check the printer status:
lpstat -p ljsn107
To cancel a print job:
cancel [ request-ID… ] [ printer… ]
lprm [ -Pprinter ] [ – ] [ job # … ]
More information about lp, lpr, lpstat, lpq, lpc, lprm and cancel can be found in the man pages.
Printing from a web browser
The web browsers in place on Red Hat Enterprise and Ubuntu Linux support printing directly from the browser. Select the print item under File, then select the desired printer, and finally select Print.
Printing from the OpenOffice suite
The OpenOffice Suite under Linux supports printing directly to system printers. Select the print item under File, then select the desired printer, and finally select Print.
Printing other kinds of files
Try opening the file that you wish to print in either its default application, editor or the document viewer (evince). This will usually be faster and end up with more usable output on the printer.
The Linux printing system supports printing many types of files directly using an lpr or lp command including: JPEG, GIF, PNG, PDF, PostScript and text.
In addition, under the GNOME Environment it can be helpful to try opening a document by double-clicking on it in the file browser, Nautilus, in order to ascertain whether Linux is able to understand the format of the file.
For more information on printing and printers please check these pages:
These UNIX manual pages may also be helpful:
enscript – convert text files to PostScript – advanced formatting
BSD Style Print Commands:
lpq – display the queue of printer jobs
lpr – send a job to the printer
lprm – remove jobs from the printer queue
System V Style Print Commands:
lpstat – display the queue of printer jobs
lp – send a job to the printer
cancel – remove jobs from the printer queue