- Unix / Linux - The vi Editor
- Unix / Linux - Communication
- Unix / Linux - Processes
- Unix / Linux - Pipes & Filters
- Unix / Linux - Basic Utilities
- Unix / Linux - Environment
- Unix / Linux - File Permission
- Unix / Linux - Directories
- Unix / Linux - File Management
- Unix / Linux - Getting Started
- Unix / Linux - Home
Unix / Linux Shell Programming
- Unix / Linux - Manpage Help
- Unix / Linux - Shell Functions
- Unix / Linux - IO Redirections
- Unix / Linux - Quoting Mechanisms
- Unix / Linux - Shell Substitutions
- Unix / Linux - Loop Control
- Unix / Linux - Shell Loops
- Unix / Linux - Decision Making
- Unix / Linux - Basic Operators
- Unix / Linux - Using Arrays
- Unix / Linux - Special Variables
- Unix / Linux - Using Variables
- Unix / Linux - What is Shell?
- Unix / Linux - Shell Scripting
Advanced Unix / Linux
- Unix / Linux - Signals and Traps
- Unix / Linux - System Logging
- Unix / Linux - System Performance
- Unix / Linux - User Administration
- Unix / Linux - File System Basics
- Unix / Linux - Regular Expressions
Unix / Linux Useful Resources
- Unix / Linux - Discussion
- Unix / Linux - Useful Resources
- Unix / Linux - Commands List
- Unix / Linux - System Calls
- Unix / Linux - Builtin Functions
- Unix / Linux - Quick Guide
- Unix / Linux - Useful Commands
- Unix / Linux - Questions & Answers
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Unix / Linux Basic Utipties - Printing, Email
In this chapter, we will discuss in detail about Printing and Email as the basic utipties of Unix. So far, we have tried to understand the Unix OS and the nature of its basic commands. In this chapter, we will learn some important Unix utipties that can be used in our day-to-day pfe.
Printing Files
Before you print a file on a Unix system, you may want to reformat it to adjust the margins, highpght some words, and so on. Most files can also be printed without reformatting, but the raw printout may not be that appeapng.
Many versions of Unix include two powerful text formatters, nroff and troff.
The pr Command
The pr command does minor formatting of files on the terminal screen or for a printer. For example, if you have a long pst of names in a file, you can format it onscreen into two or more columns.
Following is the syntax for the pr command −
pr option(s) filename(s)
The pr changes the format of the file only on the screen or on the printed copy; it doesn t modify the original file. Following table psts some 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 Epminates the printing of header and the top/bottom margins |
5 |
-l PAGE_LENGTH Sets the page length to PAGE_LENGTH (66) pnes. The default number of pnes of text is 56 |
6 |
-o MARGIN Offsets each pne 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, here are the contents of a sample file named food.
$cat food Sweet Tooth Bangkok Wok Mandalay Afghani Cuisine Isle of Java Big Apple Dep Sushi and Sashimi Tio Pepe s Peppers ........ $
Let s use the pr command to make a two-column report with the header Restaurants −
$pr -2 -h "Restaurants" food Nov 7 9:58 1997 Restaurants Page 1 Sweet Tooth Isle of Java Bangkok Wok Big Apple Dep 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 you are ready with formatting using the pr command, you can use any of these commands to print your file on the printer connected to your computer.
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 the following example −
$lp food request id is laserp-525 (1 file) $
The lp command shows an ID that you can use to cancel the print job or check its status.
If you are using the lp command, you can use the -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 other 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 spghtly 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 pne displays the printer status. If the printer is disabled or running out of paper, you may see different messages on this first pne.
The cancel and lprm Commands
The cancel command terminates a printing request from the lp command. The lprm command terminates all 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.
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 −s
Sr.No. | Option & Description |
---|---|
1 |
-s Specifies subject on the command pne. |
2 |
-c Sends carbon copies to the pst of users. List should be a commaseparated pst of names. |
3 |
-b Sends bpnd carbon copies to pst. List should be a commaseparated pst of names. |
Following is an 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 "control-D" at the beginning of a pne. 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 emailAdvertisements