Linux print files and send mail

Through the previous introduction, I believe that you have a basic understanding of Linux command and feature. This section describes if the file is printed and sent.
File Printing

If you want to print a text file, it is best to pre-process it, including adjusting the margins, setting the line height, setting the title, etc., so that the printed file is more beautiful and easy to read. Of course, it can be printed without processing, but it may be uglier.

Most Linux comes with two powerful text formatting tools, nroff and troff, but they are old and used by very few people. Interested readers can learn by themselves, and this tutorial will not explain in depth.
pr command

The pr command is used to convert a text file into a format suitable for printing. It can split a larger file into multiple pages for printing and add a title to each page.

The syntax of the pr command is as follows:
pr option(s) filename(s)
The pr command only changes the display style and printout style of the file on the screen, and does not change the file itself. The following table shows several options of the pr command:
option description
-k Print in several columns, the default is 1.
-d Double-spaced (not all versions of pr work).
-H "Header" Sets the title of each page.
-t Do not print title and top and bottom margins.
-l Page_length How much is displayed per page. The default is 66 lines per page, and 56 lines of text.
-o MARGIN The number of spaces to indent each line.
-w PAGE_WIDTH When multi-column output, set the page width, the default is 72 characters.
For example, the Food file contains a lot of food names, divided into two columns using the PR command, and sets the title of each page as "Restaurants".

First look at the contents of the file:
$cat food
Sweet Tooth
Bangkok Wok
Mandalay
Afghani Cuisine
Isle of Java
Big Apple Deli
Sushi and Sashimi
Tio Pepe's Peppers
........
$
Then use the pr command to print:
$pr -2 -h "Restaurants " 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
........
$
lp and lpr orders

The lp and lpr commands transfer files to the printer for printing. After formatting the file with the pr command, you can use these two commands to print.

The printer is usually set by the system administrator. The following example uses the default printer to print the food file:
$lp food
request id is laserp-525 (1 file)
$
The successful execution of the command will return an ID representing the print job, through this ID you can Cancel print or view the print state.

If you wish to print multiple files, use the -nNum option of lp, or the -Num option of the lpr command. NUM is a number and can be set at will.

If the system is connected to multiple printers, you can use the -dprinter option of the lp command, or the -pprinter option of the LPR command to select the printer. printer is the printer name.
lpstat and lpq Commands

The lpstat command can view the printer's buffer queue (how many files are waiting to be printed), including job ID, owner, file size, request time, and request status.

Tip: Files waiting to be printed will be placed in the printer's buffer queue.

For example, use the lpstat -o command to see all files waiting to be printed in the printer, including your own:
$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 lpstat -o command outputs the files in the queue in the order in which they are printed.

The information displayed by the lpq command is slightly different from 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 is the status of the printer. Additional information will be output if the printer is unavailable or if the paper runs out.
cancel and lprm The commands

cancel and lprm are used to terminate the print requests of lp and lpr respectively. With these two commands, either the ID (returned by lp or lpq) or the printer name needs to be specified.

For example, to cancel a print request by ID:
$cancel laserp-575
request "laserp-575" cancelled
$
If you want to cancel the file being printed, you can just specify the printer name without specifying the ID:
$cancel laserp
request "laserp-573" cancelled
$

lprm command is used to cancel the current user's files waiting to be printed. Use the task number as the parameter to cancel the specified file, and use the horizontal line (-) as the parameter to cancel all files.

For example, cancel the 575 print job:
$ LPRM 575
DFA575Diamond Dequeued
CFA575Diamond Dequeued
$ Lprm
Returns the canceled file name.
To send mail

, you can use the mail command to send and receive mail. The syntax is as follows:
$mail [-s subject] [-c cc-addr] [-b bcc-addr] to-addr
The meaning of each option is as follows:
Option description
-s Mail header.
-c Users to send, multiple users separated by commas (,).
-b Users to blind send (Bcc), multiple users are separated by commas (,).

For example, send mail to [email protected]:
$mail -s "Test Message" [email protected]
Hello everyone,
this is Linux tutorial and url is http://see.xidian.edu.cn/cpp/linux/ .
Cc:
The first line is the input command, -s indicates the subject of the email, and the following [email protected] is the recipient of the email. After entering this line of commands, press Enter to enter the writing of the email body. You can Enter any text, such as two lines above. After entering the email body, you need to press CTRL+D to end the input. At this time, you will be prompted to enter the Cc address, that is, the email copy address. The email is sent without pressing Enter.

You can also send the file through the redirection operator <:
$mail -s "Report 05/06/07" [email protected] < demo.txt
With the above command, you can use the content of the demo.txt file as the email Content sent to [email protected].

No parameters are required to receive mail:
$mail
no email

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327054031&siteId=291194637