Main index

Introducing UNIX and Linux


Files

Overview
The UNIX directory hierarchy
Filesystems
Manipulating files
      Creating directories
      Creating files
      links
      'Dot' files
Protecting files
      Groups
      File access control
      Changing privileges
File contents
      Text files
      Comparing files
      Filtering files
      Non-text files
Printing files
File archives and file compression
Other relevant commands
Summary
Exercises

Printing files

Although you will probably spend a lot of time sitting in front of a computer terminal, you will from time to time need to get 'hard copy' of documents; that is, you will need to print them onto paper. To do this, type lp ('lineprinter') followed by the name of the file or files you wish to be printed. If you omit filenames, the standard input will be printed, so that can have data piped into it. On Linux systems lpr is used instead of lp. It is important that you only attempt to print text files. Most modern printers will be sensible if you send them unprintable files, and simply refuse to print them, but a few will go haywire.

Your machine will be set up with a 'default' printer, and your system administrator should have told you which this is and where it is located. If you give to lp the option -d ('destination') followed by the name of another printer, that printer will be used instead. The option -n ('numerical') followed by a number will cause that number of copies of the document to be printed (use with care!). For instance, to print 2 copies of file myfile on the printer named def:

lp -n 2 -d def myfile

It is a fact of life that documents stored on a machine are changed frequently. When a file is sent to a printer, it is often useful for an indication to be given as to when the file was printed (so the reader will be reminded how out-of-date it may be). It is also useful, when the document is long, for each page to be printed together with a header containing useful information such as the page number. When a file is printed with lp, that file is printed completely naked; nothing except the characters in the file appear on paper. The command pr is designed to remedy this situation; it has numerous options, which allow you to tailor your files to particular printers. pr divides the input into pages, each commencing with a header naming the file and the date and time, and ending with a trailer of blank lines. The size (number of columns and width) of each page and the size of the header and trailer can be changed, output can be multi-column, and various other attributes of the output can be altered. The output of pr is sent to standard output, and so must be piped to lp. For example, the following command will print file abc on the printer named def, 2 columns per page (option -2, 50 lines per page (using option -l):

pr -2 -l 50 abc | lp -d def

To use pr effectively, you must know the characteristics of the printer (or printers) to which you have access; your system administrator should provide you with that information.

It is common nowadays for laser printers to be available. Rather than having a fixed set of characters like a line printer, or a coarse selection of symbols that can be created by an artistic user such as in a dot-matrix printer, a laser printer is suitable for intricate graphical printing. In order to use such facilities, files for a laser printer must be in a special code, such as PostScript, which most printers use for formatting documents. It is worth mentioning that most laser printers will accept text input just like other printers.


Copyright © 2002 Mike Joy, Stephen Jarvis and Michael Luck