[Unix-Linux] Basic Utilities - Printing, Email

Date:     Updated:

Categories:

Tags:

📋 This is my note-taking from what I learned in the Unix/Linux Tutorial!


Printing Files

  • Before printing a file on a Unix system, we reformat it to adjust the margins, highlight some words, and so on.
  • Most files can be printed without reformatting, but the raw printout may not be that appealing.
  • Two powerful text formatters → nroff and troff


The pr Command

If we have a long list of names in a file, we can format it onscreen into two or more columns.

pr option(s) filename(s)

pr command changes the format of the file only on the screen or on the printed copy. It doesn’t modify the original file.

pr options:

Sr.No. Option & Description
1 -k Produces k columns of output
2 -d Double-spaces the output (not on all pr versions)
3 -h "header" Takes the next item as a report header
4 -t Eliminates the printing of header and the top/bottom margins
5 -l PAGE_LENGTH Sets the page length to PAGE_LENGTH (66) lines. The default number of lines of text is 56
6 -o MARGIN Offsets each line with MARGIN (zero) spaces
7 -w PAGE_WIDTH Sets the page width to PAGE_WIDTH (72) characters for multiple text-column output only

Before using pr, the contents of a sample file named food:

$cat food
Sweet Tooth
Bangkok Wok
Mandalay
Afghani Cuisine
Isle of Java
Big Apple Deli
Sushi and Sashimi
Tio Pepe's Peppers
........
$

Make a two-column report with the header Restaurants:

$pr -2 -h "Restaurant" food
Nov  7  9:58 1997  Restaurants   Page 1

Sweet Tooth              Isle of Java
Bangkok Wok              Big Apple Deli
Mandalay                 Sushi and Sashimi
Afghani Cuisine          Tio Pepe's Peppers
........
$


The lp and lpr Commands

The command lp or lpr prints a file onto paper as opposed to the screen display. Once we format using the pr command, use any of these commands to print your file on the printer connected to our computer.

To print a file named food on the default printer, use the lp or lpr command:

$lp food
request id is laserp-525 (1 file)
$

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

  • If we use lp command, we can use the -nNum option to print Num number of copies. Along with the command lpr, we can use -Num for the same.
  • If there are multiple printers connected with the shared network, then we can choose a printer using -dprinter option along with lp command and for the same purpose we 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 we want to see all output requests other than just our 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
$

The first line laserp is ready and printing displays the printer status. If the printer is disabled or running out of paper, we may see different messages on this first line.


The cancel and lprm Commands

The cancel command terminates a printing request from the lp command. The lprm command terminates all lpr requests. We 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 print name:

$cancel laserp
request "laserp-573" cancelled
$

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

$lprm 575
dfA575diamond dequeued
cfA575diamond dequeued
$

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


Sending Email

Use the Unix mail command to send and receive mail:

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

Options related to mail command:

Sr.No Option & Description
1 -s Specifies subject on the command line.
2 -c Sends carbon copies to the list of users. List should be a commaseparated list of names.
3 -b Sends blind carbon copies to list. List should be a commaseparated list of names.

Send a test message to admin@yahoo.com:

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

Then, type in your message, followed by “control-D” at the beginning of a line. To stop, simply type dot(.) as follows:

Hi,

This is a test.
.
Cc:

Send a complete file using a redirect < operator as follows:

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

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

$mail
no email




Back to Top

See other articles in Category Unix-Linux

Leave a comment