Printing in Linux typically involves the lp command for direct printing from the terminal, but there are many ways to get your documents onto paper. If you are new to Linux or just need a refresher, learning how to print in Linux can save you time and frustration. This guide covers everything from basic commands to troubleshooting common issues, so you can print with confidence.
Linux offers several tools for printing, including command-line utilities and graphical interfaces. The most common system is CUPS (Common Unix Printing System), which manages printers and print jobs. Understanding the basics will help you handle any printing task efficiently.
Understanding Linux Printing Basics
Before you start printing, you need to know how Linux handles printers. Most modern distributions use CUPS as the backend. CUPS supports network printers, USB printers, and even shared printers from Windows or Mac systems.
You can interact with CUPS through the command line or a web interface. The web interface is accessible at http://localhost:631 in your browser. This is often easier for beginners.
Key Components Of Linux Printing
- CUPS: The core service that manages printers and print queues.
- Print Drivers: Software that translates data into printer language (like PPD files).
- Print Commands: Tools like
lp,lpr, andlpstatfor controlling print jobs. - Graphical Tools: Applications like system-config-printer or printer settings in your desktop environment.
How To Print In Linux
Now let’s get into the actual steps. Whether you prefer the terminal or a GUI, you have options. Follow these methods to start printing immediately.
Method 1: Using The Lp Command
The lp command is the standard way to print from the terminal. It is part of the CUPS package and works on almost all distributions.
- Open a terminal window.
- Check if CUPS is running:
systemctl status cups(orservice cups statuson older systems). - List available printers:
lpstat -p -d - Print a file:
lp filename.txt - Specify a printer:
lp -d printer_name filename.txt - Print multiple copies:
lp -n 3 filename.txt
For example, to print a PDF file named “report.pdf” on a printer called “OfficeJet”, you would type: lp -d OfficeJet report.pdf. The command returns a job ID you can use to track or cancel the job.
Method 2: Using The Lpr Command
The lpr command is an older alternative to lp. It works similarly but has slightly different options.
- Print a file:
lpr filename.txt - Specify a printer:
lpr -P printer_name filename.txt - Print with options:
lpr -o media=A4 filename.pdf
Both lp and lpr are interchangable in most cases. Use whichever feels more comfortable.
Method 3: Printing From A Graphical Application
Most desktop applications like LibreOffice, GIMP, or web browsers have a Print option in the File menu. This opens a standard print dialog where you can select your printer, adjust settings, and print.
- Open your document in an application.
- Go to File > Print (or press Ctrl+P).
- Choose your printer from the list.
- Adjust settings like number of copies, page range, or orientation.
- Click Print.
This method is the simplest for everyday tasks. The dialog is consistent across most applications because it uses the GTK or Qt printing framework.
Setting Up A Printer In Linux
Before you can print, you need to add a printer to your system. This process varies slightly depending on your distribution, but the steps are similar.
Using The CUPS Web Interface
- Open a web browser and go to
http://localhost:631. - Click on “Administration” and then “Add Printer”.
- Enter your root or sudo password when prompted.
- Select your printer from the list (USB, network, etc.).
- Provide a name, description, and location for the printer.
- Choose a driver from the list or provide a PPD file.
- Click “Add Printer” and then set default options.
This method works on any distribution with CUPS installed. It is reliable and gives you fine control over settings.
Using System-Config-Printer (GUI)
Many distributions include a graphical tool called system-config-printer. You can launch it from the system settings or by typing system-config-printer in the terminal.
- Open system-config-printer.
- Click the “Add” button.
- Wait for the tool to detect printers.
- Select your printer and click “Forward”.
- Choose a driver (often automatically selected).
- Apply the settings.
This tool is user-friendly and works well on Fedora, Ubuntu, and other distributions. It automatically installs necessary drivers if available.
Managing Print Jobs
Once you send a print job, you might need to check its status or cancel it. Here are the commands for managing jobs.
Checking Print Queues
Use lpstat to view pending jobs:
lpstat -oshows all jobs.lpstat -p printer_nameshows status of a specific printer.lpstat -tshows all status information.
Cancelling A Print Job
To cancel a job, use the cancel command with the job ID:
cancel job-idcancels a specific job.cancel -a printer_namecancels all jobs on that printer.
For example, if your job ID is 123, type cancel 123. You can find the job ID from the output of lpstat -o.
Holding And Releasing Jobs
Sometimes you need to pause a print job. Use lp -i job-id -H hold to hold it, and lp -i job-id -H resume to release it.
Troubleshooting Common Printing Issues
Printing problems are common in Linux, but most have simple solutions. Here are frequent issues and how to fix them.
Printer Not Detected
If your printer is not showing up, check the following:
- Ensure the printer is powered on and connected.
- Check USB cables or network connections.
- Run
lsusbto see if the system detects the printer. - Restart CUPS:
sudo systemctl restart cups.
Driver Problems
Many printers require proprietary drivers. For HP printers, install hplip. For Brother printers, download drivers from their website. For generic printers, try the gutenprint drivers.
- Install HPLIP:
sudo apt install hplip(Debian/Ubuntu) orsudo dnf install hplip(Fedora). - Install Gutenprint:
sudo apt install printer-driver-gutenprint.
Print Job Stuck In Queue
If a job is stuck, cancel it and restart CUPS. Sometimes you need to clear the spool directory manually:
- Stop CUPS:
sudo systemctl stop cups. - Remove files in
/var/spool/cups/(be careful). - Start CUPS again:
sudo systemctl start cups.
Permissions Issues
If you get “Permission denied” errors, your user might not be in the lp group. Add yourself:
sudo usermod -a -G lp $USER- Log out and back in for changes to take effect.
Advanced Printing Options
Once you are comfortable with basic printing, you can explore advanced features like duplex printing, page ranges, and printing from the command line with options.
Printing Double-Sided (Duplex)
To print on both sides, use the -o sides=two-sided-long-edge option with lp. For short-edge binding, use two-sided-short-edge.
lp -o sides=two-sided-long-edge document.pdflp -o sides=two-sided-short-edge document.pdf
Printing Specific Pages
Use the -o page-ranges= option to print only certain pages:
lp -o page-ranges=1-5 document.pdfprints pages 1 through 5.lp -o page-ranges=3,5,7 document.pdfprints pages 3, 5, and 7.
Setting Paper Size And Orientation
Specify paper size with -o media= and orientation with -o orientation-requested=:
lp -o media=A4 document.pdflp -o orientation-requested=4 document.pdf(landscape)
The orientation values are: 3 for portrait, 4 for landscape, 5 for reverse landscape, and 6 for reverse portrait.
Printing Over A Network
Network printing is common in offices. You can print to a shared printer on another Linux machine, a Windows share, or a network printer with an IP address.
Printing To A CUPS Shared Printer
If another Linux machine shares a printer via CUPS, add it using the IPP protocol:
- Open the CUPS web interface.
- Click “Add Printer”.
- Choose “IPP” and enter the URL:
ipp://ip-address:631/printers/printer-name. - Follow the prompts to install drivers.
Printing To A Windows Shared Printer
Use Samba to connect to Windows printers. Install samba-client and smbclient, then add the printer via CUPS with the smb:// protocol.
- URL format:
smb://workgroup;username:password@server/printer
Printing To A Network Printer With IP
For printers with a fixed IP, use the socket protocol (port 9100):
- URL:
socket://ip-address:9100
This works for many HP and Brother network printers.
Using Print Filters And Options
CUPS supports many options that can be passed as -o parameters. These include quality settings, color mode, and scaling.
Common Print Options
-o print-quality=5(5 is highest, 3 is normal, 4 is draft)-o ColorModel=Grayfor grayscale printing-o number-up=2to print 2 pages per sheet-o fit-to-pageto scale the document to fit the paper
You can combine multiple options: lp -o print-quality=5 -o ColorModel=Gray -o number-up=4 document.pdf
Printing From The Command Line With Lpoptions
To avoid typing options every time, set default options with lpoptions. This stores settings in ~/.cups/lpoptions.
- Set default printer:
lpoptions -d printer_name - Set default options:
lpoptions -o media=A4 -o sides=two-sided-long-edge
Now every lp command will use these defaults unless overridden.
Frequently Asked Questions
How Do I Check If My Printer Is Supported In Linux?
Check the OpenPrinting database at openprinting.org/printers. Most major brands like HP, Canon, and Brother have good support. For USB printers, you can also run lsusb and search for the model online.
Why Is My Printer Printing Garbled Text?
This usually means the wrong driver is installed. Remove the printer and add it again with the correct PPD file. For PostScript printers, try a generic PostScript driver. For PCL printers, use a generic PCL driver.
Can I Print From A Smartphone To A Linux Printer?
Yes, if the printer supports AirPrint or IPP Everywhere. Alternatively, set up CUPS with the appropriate drivers and use apps like PrintHand or Mopria Print Service on Android.
How Do I Print A PDF From The Terminal?
Use lp filename.pdf directly. CUPS handles PDF files natively. If you have issues, convert to PostScript first with pdf2ps filename.pdf filename.ps and then print the PS file.
What Is The Difference Between Lp And Lpr?
Both commands send print jobs to CUPS. lp is the newer System V style command, while lpr is the older BSD style. They have different syntax for options but perform the same function. Most users prefer lp for its consistency.
Printing in Linux is straightforward once you understand the tools. Whether you use the terminal or a graphical interface, the process is logical and flexible. Start with the basics, experiment with options, and you’ll be printing like a pro in no time. Remember to keep your system updated and drivers current for the best experience. With practice, you’ll find that Linux printing is just as reliable as any other operating system, if not more so.