Terminal 101: Printing from the Command Line

Every Monday, we’ll show you how to do something new and simple with Apple’s built-in command line application. You don’t need any fancy software, or a knowledge of coding to do any of these. All you need is a keyboard to type ’em out!

You can create and edit documents in the command line with nano, but what about printing? Well, the CUPS (Common Unix Printing System) is built into every Mac, and includes the ability to print files directly from the command line. This week, we’ll show you exactly how it’s done.

Choosing Your Printer

Nowadays, we have multiple printers connected to our systems either via USB, or a myriad of network options that are currently available.


To see a list of your connected printers, as well as list the default printer, run the following command:

lpstat -p -d

The -p asks the lpstat program to list the current printers; and, the -d tells it to list the default printer. You can optionally just use the -d flag to only list the default printer.


You can set your default printer using the following command:

lpoptions -d printerName

Replace “printerName” in the above command with the name of your printer retrieved when you ran the lpstat command (above).

Standard Printing

To print a file to your printer, use the following command:

lpr fileName

Replace “fileName” above with the path and filename of the file that you wish to print. Here, we’re printing a plain text file that was created with nano.

Printing with Options

You can print multiple copies of the same file by using the following command:

lpr -#num-copies fileName

Replace “num-copies” above with the number of copies that you wish to create; and, replace “fileName” with the path and filename of the file you wish to print.

You can also change orientations with the following command:

lp -o landscape -o fit-to-page filename.jpg

This will print in landscape orientation, fitting the file to the page. Here, we’re printing an image file named “filename.jpg.”

Viewing the Print Queue and Canceling Jobs

To view the currently queued print jobs for your printer(s), use the following command:

lpq

This will show the currently scheduled jobs for the printer. Should a job show in this area, you will get the rank, owner, job number (id), file(s), and total size of the print job.

To cancel the print, use the following command:

lprm job-id

Replace “job-id” in the above command with the job id received from running the lpq command to view the print queue. Your print will be canceled.

Cory Bohon is a freelance technology writer, indie Mac and iOS developer, and amateur photographer. Follow this article’s author on Twitter.