New Document
Unix basic utilities

The various implementations of Unix handle printing tasks in different ways. Most systems, however, understand either the BSD or System V commands, or in some cases, both. The UITS central servers at Indiana University, in particular, support both varieties. AIX, the operating system on the Research Database Complex (RDC), has its own print commands, but it also supports BSD and System V commands. This document will not cover AIX print commands.

Printing

lpr [switches] filename lpr [switches]

Replace [switches] with optional command line switches. Switches allow you to specify certain options, such as a particular printer or output format. Replace filename with the name of the file you want to print.

For example, to print a file named myfile.txt to the default printer in a system that uses the BSD-compatible commands, at the Unix prompt, enter:


lpr myfile.txt
The lp and lpr Commands:

To send a print job to a printer other than the default printer, you need to specify its name. With BSD commands, do this using the -P flag. For example, to print myfile.txt to a printer named ps99, enter:

Your system administrator has probably set up a default printer at your site. To print a file named food on the default printer, use the lp or lpr command, as in this example:

lpr myfile.txt

The lp command shows an ID that you can use to cancel the print job or check its status.

  • If you are using lp command, you can use -nNum option to print Num number of copies. Along with the command lpr, you can use -Num for the same.

  • If there are multiple printers connected with the shared network, then you can choose a printer using -dprinter option along with lp command and for the same purpose you can use -Pprinter option along with lpr command. Here printer is the printer name.

The lpstat and lpq Commands:

The lpstat command shows what's in the printer queue: request IDs, owners, file sizes, when the jobs were sent for printing, and the status of the requests.

Use lpstat -o if you want to see all output requests rather than just your own. Requests are shown in the order they'll be printed:

$lpstat -o
laserp-573  john  128865  Nov 7  11:27  on laserp
laserp-574  grace  82744  Nov 7  11:28
laserp-575  john   23347  Nov 7  11:35
$

The lpq gives slightly different information than lpstat -o:

$lpq
laserp is ready and printing
Rank   Owner      Job  Files                  Total Size
active john       573  report.ps              128865 bytes
1st    grace      574  ch03.ps ch04.ps        82744 bytes
2nd    john       575  standard input         23347 bytes
$

Here the first line displays the printer status. If the printer is disabled or out of paper, you may see different messages on this first line.

The cancel and lprm Commands:

The cancel terminates a printing request from the lp command. The lprm terminates lpr requests. You can specify either the ID of the request (displayed by lp or lpq) or the name of the printer.

$cancel laserp-575
request "laserp-575" cancelled
$

To cancel whatever request is currently printing, regardless of its ID, simply enter cancel and the printer name:

$cancel laserp
request "laserp-573" cancelled
$

The lprm command will cancel the active job if it belongs to you. Otherwise, you can give job numbers as arguments, or use a dash (-) to remove all of your jobs:

$lprm 575
dfA575diamond dequeued
cfA575diamond dequeued
$

The lprm command tells you the actual filenames removed from the printer queue.

Using System V commands:
To print in System V, use the lp command. The syntax is as follows:
 lp [switches] filename lp [switches] 

Replace [switches] with optional command line switches. Switches allow you to specify certain options, such as a particular printer or output format. Replace filename with the name of the file you want to print.

For example, to print a file named myfile.txt to the default printer in a system that uses System V commands, enter:

 lp myfile.txt
Listing print jobs

With System V, use the lpstat command to list the jobs for a particular printer. Using lpstat prints the status of all your print requests made by lp to the default or designated printer. To see the status of print jobs you have sent to the queue of the default printer that are still waiting, enter:

 lpstat
 lpstat -Pps99
 
Removing print jobs

With System V, use the cancel command to stop the printing of a file. To cancel a job, even if it's already printing, use the lpstat command to find the job number. Then use the cancel command to kill that job. For example, if you want to kill the job ps99-4, enter:

cancel ps99-4
 
Sending Email:

You use the Unix mail command to send and receive mail. Here is the syntax to send an email:

$mail [-s subject] [-c cc-addr] [-b bcc-addr] to-addr

Here are important options related to mail command:

OptionDescription
-sSpecify subject on command line.
-cSend carbon copies to list of users. List should be a comma-separated list of names.
-bSend blind carbon copies to list. List should be a comma-separated list of names.

Following is the example to send a test message to admin@yahoo.com.

$mail -s "Test Message" admin@yahoo.com 

You are then expected to type in your message, followed by an "control-D" at the beginning of a line. To stop simply type dot (.) as follows:

Hi,

This is a test
.
Cc: 

You can send a complete file using a redirect < operator as follows:

$mail -s "Report 05/06/07" admin@yahoo.com < demo.txt 

To check incoming email at your Unix system you simply type email as follows:

$mail
no email
Previous                                                                                                                                                       Next

Back to Top