Print files and send emails in Linux
Based on the previous introduction, I believe you have a basic understanding of Linux commands and features. This section describes how to print files and send emails.
File Printing
If you want to print a text file, you 'd better pre-process it, including adjusting the margin, setting the line height, and setting the title, so that the printed file is more beautiful and easy to read. Of course, it can be printed without processing, but it may be ugly.
Most Linux systems have nroff and troff powerful text formatting tools. However, they are relatively old and rarely used. Interested readers can learn them by themselves. This tutorial will not be explained in detail.
Pr command
The pr command is used to convert a text file to a suitable printing format. It can split a large file into multiple pages for printing and add a title for 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 output style of the file on the screen, and does not change the file itself. The following table lists the options of the pr command:
Option description
-K is divided into several columns for printing. The default value is 1.
-D is twice the line spacing (not all versions of pr are valid ).
-H "header" sets the title of each page.
-T does not print titles and margins.
-L PAGE_LENGTH: the number of rows per page. By default, each page contains 66 lines and 56 lines of text.
-O MARGIN: number of spaces Indented by each line.
-W PAGE_WIDTH: Specifies the page width when multiple columns are output. The default value is 72 characters.
For example, the food file contains the names of many foods. Use the pr command to split the file into two columns and set the title of each page to "batch ants ".
First, view the file content:
$ Cat food
Sweet Tooth
Bangkok Wok
Manalay
Afghani Cuisine
Isle of Java
Big Apple Deli
Sushi and Sashimi
Tio Pepe's Peppers
........
$
Then run the pr command to print:
$ Pr-2-h "Restaurants" food
Nov 7 1997 analyze ants 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 commands
The lp and lpr commands send files to the printer for printing. After formatting the file using the pr command, you can use these two commands to print the file.
The printer is generally 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)
$
If the command is successfully executed, an ID indicating the print task is returned. This ID can be used to cancel printing or view the printing status.
If you want to print multiple files, you can 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 be used to view the cache queue of the printer (How many files are waiting for printing), including the task ID, owner, file size, request time, and request status.
Tip: Files waiting for printing will be placed in the cache queue of the printer.
For example, run the lpstat-o command to view all the files waiting for printing in the printer, including your own:
$ Lpstat-o
Laserp-573 john 128865 Nov 7 on laserp
Laserp-574 grace 82744 Nov 7
Laserp-575 john 23347 Nov 7
$
The lpstat-o command outputs files in the queue in the print order.
The information displayed by The lpq command is slightly different from that displayed by 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 status of the printer. If the printer cannot be used up or the paper is used up, other information will be output.
Cancel and lprm commands
Cancel and lprm are used to terminate print requests of lp and lpr respectively. To use these two commands, you must specify the ID (returned by lp or lpq) or printer name.
For example, cancel a print request by ID:
$ Cancel laserp-575
Request "laserp-575" canceled
$
If you want to cancel a printed file, you can just specify the printer name without specifying the ID:
$ Cancel laserp
Request "laserp-573" canceled
$
The lprm command is used to cancel the file waiting for printing by the current user. You can use the task number as a parameter to cancel the specified file, and use the hyphen (-) as a parameter to cancel all files.
For example, to cancel a print task No. 575:
$ LPR 575
DfA575diamond dequeued
CfA575diamond dequeued
$
Lprm returns the canceled file name.
Send email
You can use the mail command to send and receive emails. 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 title. |
|
-C: users to be sent. Multiple users are separated by commas. |
|
-B users who need to send (send) the encrypted parts. Multiple users are separated by commas. |
For example, sending an email to a admin@yahoo.com:
$ Mail-s "Test Message" admin@yahoo.com
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 mail, followed by the admin@yahoo.com is the recipient of the mail, enter this line of command and press enter, will enter the body of the mail writing, you can enter any text, such as the above two lines. After entering the body of the email, press CTRL + D to complete the input. At this time, you will be prompted to enter the Cc address, that is, the Cc address. If you do not press enter, the email will be sent.
You can also use the redirection operator <to send files:
$ Mail-s "Report 05/06/07" admin@yahoo.com <demo.txt
With the complete command, you can send the content of the demol.txt file to the admin@yahoo.com as the mail content.
No parameters are required for receiving emails:
$ Mail
No email
This article permanently updates the link address: