Site Menu

Share

LINUX CLASSES - LINUX COMMANDS

Can I Print Linux Files?

Now that your document is free of spelling errors, why not print a copy for posterity? In Linux, the print command is lpr , (that's intuitive, right?) so to print your masterpiece, you might enter a command like this: lpr paperless-office.txt

The lpr command makes a copy of your file and stuffs it in the system's print queue (a process called spooling), so you can change or delete the original file without harming your printout.

The lpr command will accept two optional flags:

-r Delete the file after printing.

-s No spooling (don't make a temporary copy for printing).

The -r flag tells the system to delete the file after printing, and -s tells the system to print directly from the original file instead of spooling to the print queue. Of course, if you specify the -s flag, you can't modify or delete the original file while it's printing, but this option can save a bit of time (since no copy is made) when the original file is big.

Here are some examples using the -r and -s flags:

lpr -r humongous Delete the file humongous after printing.

lpr -s humongous   Print the file humongous without spooling.< /EM>

lpr -r -s humongous Print the file humongous without spooling and t hen delete it.

Customizing Your Printouts

The lpr command is a no-frills way to print your files. It doesn't do any fancy formatting; it just dumps your file on the printer. If you'd like to format your printout (paginate, add a title, set margins, or control the page length), you can use the pr command in conjunction with lpr. By default, pr will add page numbers and a title consisting of the file's name and the date and time it was last modified. But you can do lots of other fancy formatting as well. Here are some of the options that pr supports:

-d   Double-space the printout.

-h <my title>   Specify a title for the page header (the default is the file name).

-Ln   Set the page length to n lines (the default is 66).

-On   Set the margin to n characters (the default is 8).

-T   Suppress the page header.

-2 | -3 | -4   Print output in two, three, or four columns (as in a newspaper).

Typically, the output from pr is sent only to your printer (by piping the output to lpr, as shown in the following examples), but if you leave off the lpr step, you'll see the output on the screen instead. Here are some examples using the pr command to print a file named panda97.txt--for example, with no options specified, just adding page numbers and the default title (file name and date):

pr panda97.txt | lpr

Here we've specified a more meaningful title for the printout:

pr -h "Financial Report" panda97.dat | lpr

And now we've set the page length to 55 lines, set the margin to 5 spaces, and added double-spacing:

pr -h "Financial Report" -l55 -o5 -d panda97.dat | lpr

Stop the Presses!

If you send a file to the printer by mistake, you might be able to snatch it from the print queue before it's too late. First use lpq to find the job number:

lpq
Rank Owner Job Files Total Size
1st hermie 17 really-humongous 2317678 bytes

In the example shown here, the job number is 17. Once you know the job number, enlist the assistance of lprm to remove that file from the queue as follows (using job 17 as an example):

lprm 17

Previous Lesson: Spell Checking
Next Lesson: Joining Files

[ RETURN TO INDEX ]


   

Comments - most recent first
(Please feel free to answer questions posted by others!)

mohit saini     (25 Feb 2013, 18:27)
i have a problem that , i want to open a file from gnome-open command at a specific time , so what should i do , for shedule it???
Ajith     (22 Oct 2012, 04:37)
Hi all,

I'm having a printer sharing issue with open suse 12.1.

Printer connected to suse 11.3 desktop and I want to share that printer to suse 12.1 desktop.

Anyone know how to do it,

Ajith
winmac     (11 Jan 2012, 04:58)
sir i have canon ir 400 copier machine Linux should not take this canon copier what can i do? please explain me
basavaraj     (30 Dec 2011, 01:44)
hi
please help me anybody, i have install Canon LBP-2900 laser jet printer on zorin-os-4-core-32 (Ubuntu), it's installed successfully, but when i give print it's not printing & showing processing, but not printing, when i restart the printer it's showing job complied, but not printing
vidit     (29 Mar 2011, 23:56)
..soory Bob thanks
Bob Rankin     (29 Mar 2011, 07:54)
@Vidit - No, this one is correct. In the command, it is "-l55", not "-155". The letter "l" (lowercase L) precedes the "55".
vidit     (29 Mar 2011, 02:54)
.another mistake here, when u set 55 lines in commands but there are 155 lines...plz check this..
sukumar bhandari     (07 Aug 2010, 03:08)
how to automatic delete billes after printout
mujeeb     (27 Jun 2010, 05:19)
in my office Computer only one file can printing,other files cannot printing !
phc     (14 Jun 2010, 17:09)
hello
linux/ubuntu/lucid - is it possible to install a printer driver that sends all print output to a text file?, if yes, how?
thanks in advance
johnny     (07 Jun 2010, 02:47)
Hi,
You may don't have 'cups' software on your linux system. If you already installed 'cups' you should reach that.

Try to contact me if you still want help.
johnny_white007@yahoo.com
Manish     (01 Jun 2010, 02:44)
Hi,
While I am giving lpr command it gives replay like "command not found" , I am working on linux 2.6.2. can you help me?
Regards
MD

I welcome your comments. However... I am puzzled by many people who say "Please send me the Linux tutorial." This website *is* your Linux Tutorial! Read everything here, learn all you can, ask questions if you like. But don't ask me to send what you already have. :-)

NO SPAM! If you post garbage, it will be deleted, and you will be banned.
*Name:
Email:
Notify me about new comments on this page
Hide my email
*Text:
 
 


Ask Bob Rankin - Free Tech Support


Copyright by - Privacy Policy
All rights reserved - Redistribution is allowed only with permission.