File printing
If you want to print a text file, it's best to pre-process it, including adjusting the margins, setting the row height, setting the caption, and so on, so that the printed file is more aesthetically pleasing and easier to read. Of course, it can be printed without processing, but it may be ugly.
Most of Linux comes with Nroff and troff two powerful text formatting tools, but older, few people, interested readers can learn by themselves, this tutorial is no more in-depth explanation.
PR command
The PR command is used to convert a text file into a format suitable for printing, which splits large files into multiple pages for printing, and adds titles to each page.
The syntax for 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 is a few options for the PR command:
Options |
Description |
-K |
Print in several columns, default to 1. |
-D |
Twice spacing (not all versions of PR are valid). |
-H "Header" |
Sets the title of each page. |
-T |
Does not print the title and the top and bottom margins. |
-L Page_length |
How many rows are displayed per page. By default, there are 66 rows for each page and 56 lines for the text. |
-O MARGIN |
The number of spaces to indent per line. |
-W Page_width |
When multiple columns are output, the page width is set to 72 characters by default. |
For example, the food file contains the names of many foods, is printed in two columns using the PR command, and the title of each page is "restaurants".
First look at the contents of the file:
$cat foodsweet Toothbangkok Wokmandalayafghani cuisineisle of Javabig Apple Delisushi and Sashimitio Pepe ' s Peppers .... .$
Then use the PR command to print:
$PR-2-H "restaurants" Foodnov 7 9:58 1997 restaurants Page 1Sweet tooth Isle of Javabangkok wok
big Apple delimandalay Sushi and Sashimiafghani cuisine Tio Pepe ' s peppers........$
LP and LPR Commands
The LP and lpr commands transfer files to the printer for printing. Using the PR command to format the file, you can use both commands to print.
The printer is typically set by the system administrator, and the following example prints the food file using the default printer:
$LP foodrequest ID is laserp-525 (1 file) $
Successful execution of the command returns an ID that represents the print task, which allows you to cancel printing or view the print status.
If you want to print multiple files, you can use the-nnum option for LP, or the-num option for the LPR command. Num is a number that can be set arbitrarily.
If the system is connected to more than one printer, 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.
Description of the parameters of the command for LP:
2. Use
LP is a command to print files, and the use of permissions is for all users.
2. Format
LP [-c][-d][-m][-number][-title][-p]
3. Main parameters
-C: Copy the file before printing.
-D: Print the queue file.
-M: Send e-mail to the user after printing ends.
-number: Number of copies printed.
-title: Prints the title.
-P: Sets the priority level for printing, up to 100, and 50 by default.
4. Application examples
(1) Print multiple files using LP command
#lp 2 3 4
Request ID is one (3 file (s))
Where 2, 3, and 4 are filenames; "Request ID is one (3 file (s))" means this is the 11th Print command, which prints the three files in turn.
(2) Set the print priority level
#lp lp-d laserjet-p 90/etc/aliases
By adding "-P 90", the priority of the print job is 90. It will print before a print job with a priority lower than 90, including jobs with no priority, with a default priority of 50.
Lpstat and LPQ commands
The lpstat command can view the printer's cache queue (how many files are waiting to be printed), including the task ID, owner, file size, request time, and request status.
Tip: Files waiting to be printed are placed in the printer's cache queue.
For example, use the lpstat-o command to view all the files in the printer that are waiting to be printed, including your own:
$lpstat-olaserp-573 John 128865 Nov 7 11:27 on laserplaserp-574 Grace 82744 Nov 7 11:28laserp-575 John 23347 Nov 7 11:35$
The Lpstat-o command outputs the files in the queue in print order.
The lpq command displays slightly different information than Lpstat-o:
$lpqlaserp is ready and Printingrank Owner Job Files Total sizeactive John 573 report.ps 128865 bytes1st Grace 574 ch03.ps ch04.ps 82744 bytes2nd John 575 Standard Input 23347 bytes$
The state of the first behavior printer. If the printer is not available or the paper is exhausted, additional information will be output.
The LPQ command is used to display status information for print tasks in the print queue. -E: Force the use of encryption to connect to the server;-P: Displays the status of the print queue on the printer,-u: automatic optional user name;-A: Reports all printer definition tasks;-h: Specifies print server information;-L: Use long format output; +: Specifies the time interval for display status.
From: HTTP://MAN.LINUXDE.NET/LPQ
From: Http://man.linuxde.net/lpqcancel and LPRM commands
Cancel and LPRM are used to terminate the print requests for LP and LPR respectively. With these two commands, you need to specify the ID (returned by LP or LPQ) or the printer name.
For example, cancel the print request by ID:
$cancel laserp-575request "laserp-575" cancelled$
If you want to cancel the file you are printing, you can specify the printer name without specifying the ID:
$cancel laserprequest "laserp-573" cancelled$
The LPRM command cancels the current user's pending print file, uses the task number as a parameter to cancel the specified file, and uses the horizontal line (-) as the parameter to cancel all the files.
For example, cancel the No. 575 Print task:
$LPRM 575dfa575diamond Dequeuedcfa575diamond dequeued$
LPRM will return the file name that was canceled.
Send mail
You can use the Mail command to send and receive messages with the following syntax:
$mail [-S subject] [-C CC-ADDR] [-B bcc-addr] To-addr
Each option has the following meanings:
Options |
Description |
-S |
The message header. |
-C |
to send a user, multiple users are separated by commas (,) . |
-B |
Users who require BCC (secret send), multiple users separated by commas (,). |
For example, send mail to [email protected]:
The first line is the input command,-s to indicate the subject of the message, the following [email protected] is the recipient of the message, enter the line after the command entered, will enter the message body writing, you can enter any text, such as the above two lines. After entering the body of the message, you need to press Ctrl+d to end the input, you will be prompted to enter the CC address, that is, the mail cc address, no direct return to complete the message sent.
You can also send files via the redirect operator <:
$mail-S "Report 05/06/07" [email protected] < Demo.txt
With the above command, the contents of the demol.txt file can be sent to [email protected] as the content of the email.
No parameters are required to receive the message:
$mailNo email
Linux Learning Series 6---Print files and send mail