Software & AppsOperating SystemLinux

Printing from Command Line in Ubuntu Server 12.04

Ubuntu 17

In this article, we will delve into the world of command line printing in Ubuntu Server 12.04. This is a useful skill to have, especially when working with servers, as it allows you to print documents directly from the command line. We will cover several methods, including using the lp and lpr commands, using pipes, and using enscript or a2ps for more advanced options.

Quick Answer

Printing from the command line in Ubuntu Server 12.04 is possible using the lp and lpr commands. Simply use the command lp /path/to/file or lpr /path/to/file to send a file to the default printer. You can also use pipes to print the output of a command directly, and for more advanced options, tools like enscript or a2ps can be used.

Using the lp or lpr Command

The lp and lpr commands are the basic commands for printing in Linux. They send a file to the printer for printing. Here’s how to use them:

lp /path/to/file

or

lpr /path/to/file

In these commands, replace /path/to/file with the actual path to the file you want to print. These commands will send the file to the default printer.

The lp command has several options you can use to customize the print job. For example, the -d option allows you to specify the printer to use:

lp -d printername /path/to/file

In this command, replace printername with the name of the printer you want to use.

Using Pipes

If you want to print the output of a command directly, you can use pipes (|) to redirect the output to the lp or lpr command. Here’s how:

ls -l | lp

This command will print the output of the ls -l command. The ls -l command lists the files in the current directory in long format, and the | symbol pipes this output to the lp command, which sends it to the printer.

Using enscript or a2ps for Advanced Options

If you need more control over the layout, fonts, and other options, you can use tools like enscript or a2ps. These tools allow you to format and print plain text files with various options.

First, you need to install enscript:

sudo apt install enscript

Then, you can use it like this:

your_command | enscript -P printername -f fontname@fontsize

In this command, replace your_command with the command whose output you want to print, printername with the name of the printer you want to use, and fontname@fontsize with the desired font and font size.

Conclusion

Printing from the command line in Ubuntu Server 12.04 is a versatile and powerful feature that can save you time and effort. Whether you’re using the basic lp or lpr commands, piping output directly to the printer, or using advanced formatting tools like enscript or a2ps, you have a wide range of options at your disposal.

Remember to always ensure that you have the necessary printer drivers installed and that the printer is properly configured on your system. For more information on how to do this, you can consult the Ubuntu Server documentation.

So, go ahead and start printing from the command line. It’s a skill that will serve you well in your work with Ubuntu Server.

How can I check the available printers in Ubuntu Server 12.04?

To check the available printers, you can use the lpstat -p command. This will list all the printers configured on your system.

How can I set a default printer in Ubuntu Server 12.04?

To set a default printer, you can use the lpoptions -d printername command. Replace printername with the name of the printer you want to set as the default.

Can I print multiple copies of a file using the command line?

Yes, you can print multiple copies by adding the -n option followed by the number of copies you want to print. For example, lp -n 5 /path/to/file will print 5 copies of the specified file.

How can I check the status of a print job?

You can use the lpstat -W command to check the status of all print jobs. This will display information such as job ID, user, and status for each print job in the queue.

How can I cancel a print job?

To cancel a print job, you can use the cancel jobID command. Replace jobID with the ID of the print job you want to cancel. You can obtain the job ID from the output of the lpstat command.

Can I print a specific page range of a document?

Yes, you can print a specific page range by using the -o page-ranges=start-end option with the lp or lpr command. Replace start and end with the page numbers you want to print. For example, lp -o page-ranges=1-5 /path/to/file will print pages 1 to 5 of the specified file.

How can I print a PDF file from the command line?

You can use the lp or lpr command to print a PDF file. Simply provide the path to the PDF file as the argument. For example, lp /path/to/file.pdf will send the PDF file to the default printer for printing.

Can I print files from a remote server using the command line?

Yes, you can print files from a remote server by using the ssh command in combination with the lp or lpr command. For example, ssh user@remote_server "lp /path/to/file" will print the specified file on the remote server.

How can I print a text file with custom formatting options?

You can use tools like enscript or a2ps to print text files with custom formatting options. These tools allow you to specify fonts, font sizes, headers, footers, and more. Refer to the section on "Using enscript or a2ps for Advanced Options" in this article for more details.

How can I check the printer queue in Ubuntu Server 12.04?

You can use the lpq command to check the printer queue. This will display information about the print jobs in the queue, such as job ID, size, and status.

Leave a Comment

Your email address will not be published. Required fields are marked *