Pin Me

The Basics of Linux Printing From the Command Line

written by: Sam OBrien•edited by: Lamar Stonecypher•updated: 6/22/2010

Have you ever wondered how printing from a Linux command line works? Although it's a rare occurrence, graphical user interfaces (GUIs) can and do "break." Learn Linux printing from a terminal to be prepared for such times.

  • slide 1 of 4

    Most users of Unix-like operating systems rely totally on the graphical user interfaces (GUIs) now provided for almost every task for all types of system management from configuring a printer to managing software and multiple users. However, there's a reason why all professional credentials that truly reflect a person's Linux qualifications can only be earned by demonstrating the knowledge of how to efficiently and securely work from within a terminal or console. Of course this includes Linux printing on the the command line. It isn't difficult if you grasp the basic concepts and are careful with the commands you issue. Yes, there is more risk of causing problems when working in a terminal. However, with greater "power" and freedom comes more responsibility.

  • slide 2 of 4

    Basic Linux Printing Commands

    If you gain a working knowledge of the following basic commands, you'll be able to accomplish much without a GUI.

    1. lp (line printer spooling) - used to print a document using a designated printer

    2. lpc (line printer control) - used by the root user or system administrator to manage things such as spooling, the lpd daemon, activity, and status of a printer whether networked or not.

    There are other commands and subsets of these commands that relate to each of the above; they are provided by the common Unix printing system (CUPS) used by Unix and Unix-based systems such as the various distributions of Linux. Again, learning to work with those I've mentioned accomplishes much when it comes to Linux printing on the command line.

  • slide 3 of 4

    Putting Those Commands to Work

    If you click on the screen shot below, you can see how I've accomplished printing from a Linux command line. I'm working as root, but you don't have to if you don't want to or don't have root or superuser privileges on the machine to which you have access. However, I do suggest practicing as root to work with the lpc command. You can practice by creating short test text (.txt) files to print; create at least three. I've done everything within a terminal such as using the touch command to create the file and the vi editor with which I often work and am quite comfortable. Again, you don't have to do this to work with Linux printing on the command line; however, you should have knowledge of the most basic Unix commands because, in this article, I explain only the ones that specifically have to do with Linux printing.

    Next, I issued the lpc command which changed the prompt to lpc> after which I typed help and received a little assistance from the system which listed five more commands I could use. You can also see how I issued ? to pretty much get the same list to which the comment, "Commands may be abbreviated. Commands are:" was added. Typing exit or quit will take you back to your original prompt while status will report on the status of printers as you can see I've done for the one HP printer I have connected to this machine running Fedora 8.

    To print a document or several documents, use the lp command, specify the name of the printer, and the name of the document. For example, lp -ddeskjet_3320 test1.txt test2.txt test3.txt. I could also have achieved the same results by using wildcard capabilities; so, test1.txt test2.txt test3.txt could have simply been *.txt which would have "grabbed" all of the .txt files in the Desktop directory. Be careful with the wild card or you could end up having to cancel a lot of jobs. You can't just type in the name of your printer, rather you must use the name reported by the system as shown in the screen shot which was used during printer configuration. I couldn't have issued the command using dskjt3320 or any variation of the printer name, but rather I had to use the exact name reported in the status. The -d is the option to pass to the command just before naming the printer; you can think of it as standing for document/s. You can also see that I requested another status during printing which revealed "1 entries" in the report. If you would like to continue learning Linux printing, you'll want to advance to knowing how to view the documents in queue, cancel print jobs, manage print spooling, the lpd daemon, printer configuration, and much more. The commands covered here are only the beginning. Again, with this knowledge of Linux printing, you could at least print out needed documents from a command line if no GUI was available.

  • slide 4 of 4