1. You are here:
  2. DSV
  3. Education
  4. Computer facilities
  5. Linux
  6. Linux printing

Linux printing

There are a number of laser printers available to students for printing. In graphical programs there are usually an icon or a command in the pulldown menus to ask for a printout. If you however want to print a text file without starting a text editor, or print a PostScript file without starting a PostScript reader, you can use the programs lpp or a2ps. Below are tips on how to use them.

PostScript

Most printers at DSV are PostScript printers. It means that all print jobs sent to them must be programs in the page description language PostScript. There are a number of programs that generate PostScript code but it is also technically possible to write your own PostScript programs. There are also a special version call Encapsulated PostScript (EPS). An EPS program is written so that it can be included in another PostScript program without trouble.

Printing a text file

To print text files (for example an e-mail or source code) in GNU/Linux, the easiest is to use the program lpp or a2ps. These programs convert the text to PostScript and send it to the printer in one single command.

lpp

This is syntax of the lpp program:

lpp [flags] [file...]

Below some of the flags for lpp are shown:

-P printer
Send the print job to the printer printer.
-4
Choose A4 format
-bdi
Adds no borders, date or page heads.

For more information abot the different flags for lpp enter the UNIX command "man lpp".

a2ps

This is the syntax of the a2ps program:

a2ps [flags] [file...]

Below are some of the many flags for a2ps:

-P printer
Send the print job to the printer printer.
-B
No page head.

See "man a2ps" for complete information.

Printing PostScript

The program lpr (lineprinter) is used for printing PostScript files. Programs such as for instance the LaTeX system, Xfig och Xv can produce PostScript for printing on their own. PostScript files usually have the file ending ".ps". This is the syntax for lpr:

lpr [flags] [file...]

It is not necessary to give any flags, and if lpr is used as the receiver of a pipe no file names are necessary. Below are some of the most useful flags for lpr. There are many more.

-P printer
Send the print job to the printer printer.
-h
Don't print the banner page (user name, work station and more).
-w n
Limit the width of every row to n characters.
-m
Send an e-mail when the print job is done.

Where does the printout end up?

Unless the print job is directed explicitly with the P-flag to lpr (it also works with lpp and a2ps), the printout either comes to the printer in the environment variable PRINTER or, if the variable has no value, to the printer defined as default for the current PC. You can check your PRINTER variable by entering the following into a terminal window:

echo $PRINTER

If you temporarily want do set the variable to another printer, for example sushi, then write:

export PRINTER=sushi
If you want to change the printer permanently then you should put the same command at the end of the file .profile which is located in your home directory. First control with echo that $PRINTER does not have a suitable value.

Look in the printer queue

The command for looking at the printer queue is lpq. It has the following syntax:

lpq [flags] [job number...] [user...]

None of the arguments are necessary.

-l
Use more than one line per job if necessary (long listing).
-P printer
Show the queue for the printer printer.
job number...
Show only the status of the listed job numbers.
user...
Show only the statis of the listed users.

Remove a job from the queue

lprm is used to remove a job from the print queue. It has the following syntax:

lprm [-P printer] [-] [job number...]

If the command is given without any arguments the current job is removed, if it is owned by the issuer of the command.

-P printer
Removes jobs queued to the printer printer.
-
Removes all jobs that are owned by the user.
job number...
Removes the listed job numbers.

Examples of print commands

lpp foo.txt
Prints out the text file foo.txt on the printer given by the environment variable PRINTER.
a2ps bar.txt
Prints out the text file bar.txt on the printer given by the environment variable PRINTER.
lpp -4 foo.txt
Prints in A4 size.
ls -l | lpp
Prints a long listing of the current file directory.
lpr foo.ps
Prints the PostScript file foo.ps.
lprm -
Removes all print jobs from the printer queue.
In cooperation with KTH.