lpd: Getting the Hard Copy
In the 16th century, the printing press opened up a whole new world of communications. Print was the first mass communications medium, paving the way for books, magazines, newspapers and all the other amenities of this generation. Although we live in a world dominated by computers and electronics, the printing press still plays an important role in our everyday lives. This fact is especially apparent if you are reading the print version of this magazine.
Today, the power of the printing press is available to the individual. Computers, printers and copy machines allow virtually anyone to communicate effectively to any number of people. Better still, it's easier and cheaper than ever.
One of the most common questions asked by newcomers to the Linux world is how to get their printers working with Linux. There are, in actuality, a few different ways to accomplish this task. First, however, you must enable lp support in the kernel and recompile. This is done in most kernels already. To check if your kernel is ready, plug your printer in and watch your kernel startup messages. If you see references to lp0 or lp1, your kernel is configured for parallel printing.
The most primitive way to print a text file is simply to use the cat command to send it to the printer at /dev/lp1:
cat filename.txt > /dev/lp1
This will catenate the file (in this case, filename.txt) to /dev/lp1, your printer device. Replace /dev/lp1 with the device name of your printer, if it is different.
The main problem with printing text files this way is that most people get the dreaded “staircase” effect. It makes the printed text look
Something Like This.
This is not acceptable, so most people use lpd (line printer daemon) to print files. If you don't have lpd already installed, it is obtainable from ftp://metalab.unc.edu/pub/Linux/system/printing/ as the lpr-linux package. Once you have downloaded and installed the software, you can add the following lines to one of your startup scripts, in order to start lpd when the system boots.
if [ -f /usr/sbin/lpd ]; then echo -n "Starting lpd..." /usr/sbin/lpd fiYou might want to replace the path to lpd with your custom path.
However, running lpd alone isn't very useful. All it actually does is facilitate the queueing of print jobs. It does no translating or converting—that's why print filters are used. As you may know, many Linux and X applications can output and print to PostScript. This includes Netscape and the GIMP. To take advantage of these powerful applications and many others, you have to install a filter for your specific printer. Several different printer filter packages are available, so almost all popular printers are supported.
To install a filter, the first thing you must do is download the one you want. Many filters are available from the Sunsite Linux archives at ftp://metalab.unc.edu/pub/Linux/system/printing/.
The most popular print filters are apsfilter and magicfilter. In addition to the major print filters, there are many small converters and translators as well as other printer filters available for download at metalab. After you have downloaded the package you want, just follow the directions provided and install the package. (Note that metalab.unc.edu used to be sunsite.unc.edu.)
Now comes the tricky part. The lpd software reads from a configuration file called the printcap, or printer capability database. The printcap is a simple text file that holds the information necessary for lpd to output to printers. It has vast capabilities and options, but we're going to edit it in only the simplest ways right now. Fire up your favorite text editor and open the file /etc/printcap. If there is text currently in the file, make sure you don't need it (it's all commented and annotated), and comment out unneeded lines by placing a # symbol in front of the first character of those lines.
At this point, you are ready to start entering printer information into the file. Make sure you have installed your print filter correctly before proceeding.
Append this one line to your /etc/printcap file:
First, replace name with the name of your printer. Second, replace lpx with the device name of your printer, which is probably lp1. Finally, replace /path_to/print_filter with the actual path to your print filter. You must remember to change the permissions of your installed print filter so that it is executable and readable. Simply type:
chmod 755 /Also, make sure the print spool directory, /var/spool/lpd, exists. If you want to print to a remote printer on another UNIX machine, set up the printer on that machine, then append (don't start a new line)
rm=remotehost:rp=remoteprinter:to the previous /etc/printcap entry shown above. If you decide to do this, however, replace :lp=/dev/lpx: with a plain :lp=:. For more options to put in the printcap file, look at the man page for printcap (type man printcap at the prompt).
Now, restart lpd by issuing the following command:
killall -HUP lpd
There should be a brief pause, then you will be dropped back to a command prompt. If you've followed these directions correctly, do a test print: fire up Netscape and print a test page. Click on the File menu and select “Print” or “Print Frame”. Make sure the Print Command field is set to
lpr -Of course, replace printername with the name you gave your printer in /etc/printcap. There is no space between the -P and printername. To print text files, you can open them up in a program that is printer-aware (such as Netscape), or you can type the following on a command line:
lpr -Replace printername with the printer's name and replace filename with the name of the file you want to print. At this point, if all went according to plan, there should be a nicely printed piece of paper on your printer.
Fast/Flexible Linux OS Recovery
On Demand Now
In this live one-hour webinar, learn how to enhance your existing backup strategies for complete disaster recovery preparedness using Storix System Backup Administrator (SBAdmin), a highly flexible full-system recovery solution for UNIX and Linux systems.
Join Linux Journal's Shawn Powers and David Huffman, President/CEO, Storix, Inc.
Free to Linux Journal readers.Register Now!
- Download "Linux Management with Red Hat Satellite: Measuring Business Impact and ROI"
- Petros Koutoupis' RapidDisk
- ServersCheck's Thermal Imaging Camera Sensor
- The Italian Army Switches to LibreOffice
- Linux Mint 18
- Oracle vs. Google: Round 2
- The FBI and the Mozilla Foundation Lock Horns over Known Security Hole
- Privacy and the New Math
- Varnish Software's Varnish Massive Storage Engine
Until recently, IBM’s Power Platform was looked upon as being the system that hosted IBM’s flavor of UNIX and proprietary operating system called IBM i. These servers often are found in medium-size businesses running ERP, CRM and financials for on-premise customers. By enabling the Power platform to run the Linux OS, IBM now has positioned Power to be the platform of choice for those already running Linux that are facing scalability issues, especially customers looking at analytics, big data or cloud computing.
￼Running Linux on IBM’s Power hardware offers some obvious benefits, including improved processing speed and memory bandwidth, inherent security, and simpler deployment and management. But if you look beyond the impressive architecture, you’ll also find an open ecosystem that has given rise to a strong, innovative community, as well as an inventory of system and network management applications that really help leverage the benefits offered by running Linux on Power.Get the Guide