The lpr Command


The lpr Command

Because Unix is a multiuser environment, it would only make sense that more than one person would be printing to a printer at any single time. When you print in Unix, your print job is sent with a print job number. This number is assigned to the job by Unix to track and complete the job. Canceling a print job after you start one is canceled based on that job number. The job is removed from the print queue and then you no longer have a print job pending.

Now that you understand the fundamentals of printing in Unix, let's take a look at how to actually get it done.

With the lpd (line printer daemon and its protocol) system available on your machine, you can use the lpr suite of commands to send print jobs to your printer. The lpr (line printer) command is the primary method for sending data to the printer and is available on most, if not all, Unix systems unless disabled or removed. lpr essentially dumps all data directly to the printer that you specify. To use lpr, follow these steps:

1.

Determine the name of the printer you want to use. In some cases, your Unix system administrator will give you the name.

2.

Choose the file you want to print such as a text file. If you do not have one to print, make one with emacs or vi.

3.

Send the print job by using the following command: lpr -P<printer name> <filename> <filename>.... (There is no space between the -P and the printer name.)

4.

If there is only one printer configured on your computer, chances are you can simply type lpr <filename> <filename>....

Let's look at an example of how to print out a print job. As an example, type the following:

 >lpr Ppr1 anyfile.txt 

Printing, Printer, Print Server, Print Queue… What? There are a lot of terms to understand, and if you really want to learn how printing works you will need to know the details. Printing can be confusing if you do not understand all the terminology revolved around it.

For one, printing is the process for reproducing copies of texts and images on the Unix system. A printer is the device used to do the actual printing work. A printer is a peripheral hardware device that produces a hard copy (permanent human-readable text and/or graphics, usually on paper) from data stored in a computer connected to it or from another source. A print server is generally the computer and/or software that is used to provide users or a network with access to a central printer. The print server shares resources and collects its jobs in its print queue (mostly found on the print server but in some cases can also be on the local system). The print server then sends the print jobs to the hardware printer. The printer server acts as a buffer, holding the information to be printed out in memory until the printer is free and clear. It is possible to program the print server to print jobs in the order they arrive, or to give priority to particular users who need it. If you need to remove a job from the queue, only the root user or the person who owns a print job can remove it from the queue. A print job is the job you sent to the printer. The job is nothing more than what you want done.

This should clear things up so you can master the rest of the lesson. Make sure you clearly understand these definitions before moving on.


The result of this command is that the file anyfile.txt is sent to the printer named pr1. If the printer is not busy, then the print job will be printed immediately. If the need arises, you may need to print multiple copies of a document. You can do this by entering the same command once for each copy you need, or by simply specifying the number of copies as an option to the lpr command.

No Print Job for You! You may not be able to print because you are not configured to do so. Running the lpr command may give you an error such as "no default destination available" or some other error (it will be different based on your Unix version) that simply states that you do not have a destination device for your hardware printer to send the job to. Because of this, Unix just tells you "sorryno print job for you!"


Specify the number of copies as an option to the lpr command by doing the following: type lpr with -#<number of copies> to print that many copies of each file in the job. That's it!

Also, there are a few file formats and special print cases that might require special attention from the print command. Filters are applied to a file to convert the information to a special format. The format can be any that the printer can handle. Here are a few examples of common filters:

  • .ps This extension stands for postscript files. Postscript files will be handled automatically by the lpr command. You can print them as you print a plain text file.

  • .dvi This extension stands for text files. Files from text contain special page layout instructions. You can use the -d option with lpr in order to print these files correctly.

  • .tr This extension stands for troff files. This is the standard file format for man pages. You can use the -t option to print out a man page.

Now you know how to print with Unix, and some of the commands you can use to send jobs to a printer. We now need to know how to check the status of a print job, so that if a problem occurs it can be dealt with quickly.

My Cups Runneth Over… CUPS, or the Common Unix Printing System, also uses filters. CUPS is the newer model that Unix and Linux are based on, which is more standardized.

CUPS is a modular Unix printing system that allows your system to act as a print server. CUPS was designed to be easier to network than standard Unix printing solutions. CUPS consists of a Unix print spooler, a scheduler, as well as a filtering system.

When using CUPS, you will see a big advantage in that it can process a variety of formatted data to the print server through the use of its filters. It converts the print job data into the format the printer will understand. CUPS does this using MIME (Multipart Internet Mail Extensions) types. MIME is an Internet Standard for the format of email, but is commonly used in other systems to determine the type of file that is being processed.


Spooling A print spooler is a program that holds (stores) documents that are to be printed. This is the program that manages the handling of the data from the print requestor (you), to the print device (the printer). Jobs are spooled into the queue where they await their turn to print.




    SAMS Teach Yourself Unix in 10 Minutes
    Sams Teach Yourself Unix in 10 Minutes (2nd Edition)
    ISBN: 0672327643
    EAN: 2147483647
    Year: 2005
    Pages: 170

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net