Печать в консоли linux

How can I print the command line output directly to the printer. I am using ubuntu server 12.04 and I have to copy files into a shared directory and then download them from a desktop ubuntu distribution to print them. Any help is appreciated

You didn’t say if you’ll be printing plain text or PDF. Some systems only support plain text out of the box, so this needs to be covered.

8 Answers 8

Mainly there are two default commands:

lpr submits files for printing. Files named on the command line are sent to the named printer (or the default destination if no destination is specified). If no files are listed on the command-line, lpr reads the print file from the standard input.

lp submits files for printing or alters a pending job. Use a filename of «-» to force printing from the standard input.

so easily use the command:

man firefox | lp -d printername 

This will print the man page from firefox to the specified printer

Thanks, I also needed to use o fit-to-page to keep the text on the page a bit better. man bash | lp -o media=letter -o portrait -o fit-to-page — , the — at the end ensures standard input is read.

If your printer is default you don’t need the -d parameter. On Ubuntu with Unity, the default printer is set by clicking on the Search button then type «print» and it will take you to the right place where the default can be set. Also, lp in the example says you have been around Unix for some time. lpr works the same on Ubuntu.

If you have them installed, another pair of options worth knowing about are

These are useful for providing numbered pages with headings and optional line-numbers. You can also use then to print booklet style (e.g. two pages on each side of a sheet)

I use these with Postscript-capable printers but I believe that Ubuntu’s print system can rasterize PS for any supported printer.

You may want to find out how the printer is accessed first — lpstat will give you that information. If you compare its output across both systems, you can probably tell whether the printer in question has been configured on both of them. lpstat -p -d lists all printers with their status and tells which one has been set as default printer.

You can simply pipe your output to the lp or lpr command then. You may want to insert a filter for pretty-printing or pagination though. There’s a good summary of tools at the debian manual «Highlighting and formatting plain text data», but I’m usually just using sed to highlight prompts and other stuff before sending everything through a2ps

Читайте также:  Резервное копирование баз 1с postgresql linux

To print a .txt file in a use :

command | lpr -P printername -p ( periority from 1 to 100 ) 
ls -l | lpr -P printername -p 1 

You can use the lp command.

To print the output of a command to the default printer (use lpstat -d to see what the default printer is):

To print to a specific printer (use lpstat -p | awk » to list available printer names):

echo "test" | lp -d printername 

To print a file, rather than a command output:

The question is about how to print from the command line on a server, and it sounds like you don’t yet have any printers defined on that system. I don’t have a system to check on so the following are approximate, but they should give you the general idea:

  1. Make sure the CUPS system is installed and running. It provides the daemons that will handle your print jobs.
  2. Once this is up, you need to set up one or more network printers to print to. The usual way to install printers is with the Printer Admin utility, but you evidently aren’t set up to run any GUI programs from your server— just commandline access via ssh. Since you already have an Ubuntu desktop system on the same network, I’d try copying the contents of the directory /etc/cups from the desktop box to the server. It should contain all the printer definitions and drivers you need. Check the files for any necessary adjustments (in case your set-up mentions user IDs or passwords that differ between the two systems), restart cupsd , and if you’re lucky you’ll be able to use lpr to print from the commandline.

PS. In a pinch, you could install enough X utilities to run the Print Admin GUI utility via a remote X connection to your desktop Ubuntu box (log in with ssh -X ), and define the printers you need. But hopefully this won’t be necessary.

Источник

Linux и Android

Печать из командной строки Linux очень проста. Вы используете команду lp, чтобы запросить печать, и lpq, чтобы увидеть, какие задания на печать находятся в очереди, но все становится немного сложнее, когда вы хотите печатать на двух сторонах листа или в портретном режиме. И есть много других вещей, которые вы можете захотеть сделать — например, распечатать несколько копий документа или отменить задание на печать. Давайте проверим некоторые опции, чтобы, когда вы печатаете из командной строки, ваши распечатки выглядели именно так, как вы хотите.

Чтобы просмотреть настройки принтера из командной строки, используйте команду lpoptions. Вывод должен выглядеть примерно так:

$ lpoptions
copies=1 device-uri=dnssd://HP%20Color%20LaserJet%20CP2025dn%20(F47468)._pdl-datastream._tcp.local/ finishings=3 job-cancel-after=10800 job-hold-until=no-hold job-priority=50 job-sheets=none,none marker-change-time=1553023232 marker-colors=#000000,#00FFFF,#FF00FF,#FFFF00 marker-levels=18,62,62,63 marker-names='Black\ Cartridge\ HP\ CC530A,Cyan\ Cartridge\ HP\ CC531A,Magenta\ Cartridge\ HP\ CC533A,Yellow\ Cartridge\ HP\ CC532A' marker-types=toner,toner,toner,toner number-up=1 printer-commands=none printer-info='HP Color LaserJet CP2025dn (F47468)' printer-is-accepting-jobs=true printer-is-shared=true printer-is-temporary=false printer-location printer-make-and-model='HP Color LaserJet cp2025dn pcl3, hpcups 3.18.7' printer-state=3 printer-state-change-time=1553023232 printer-state-reasons=none printer-type=167964 printer-uri-supported=ipp://localhost/printers/Color-LaserJet-CP2025dn sides=one-sided

Этот вывод, вероятно, будет немного более дружественным к человеку, если вы превратите его пробелы в возврат каретки. Обратите внимание, сколько настроек указано в списке.

Читайте также:  Linux подавить вывод команды

ПРИМЕЧАНИЕ. В приведенном ниже выводе некоторые строки были повторно связаны, чтобы сделать этот вывод более читабельным.

$ lpoptions | tr " " '\n' copies=1 device-uri=dnssd://HP%20Color%20LaserJet%20CP2025dn%20(F47468)._pdl-datastream._tcp.local/ finishings=3 job-cancel-after=10800 job-hold-until=no-hold job-priority=50 job-sheets=none,none marker-change-time=1553023232 marker-colors=#000000,#00FFFF,#FF00FF,#FFFF00 marker-levels=18,62,62,63 marker-names='Black\ Cartridge\ HP\ CC530A, Cyan\ Cartridge\ HP\ CC531A, Magenta\ Cartridge\ HP\ CC533A, Yellow\ Cartridge\ HP\ CC532A' marker-types=toner,toner,toner,toner number-up=1 printer-commands=none printer-info='HP Color LaserJet CP2025dn (F47468)' printer-is-accepting-jobs=true printer-is-shared=true printer-is-temporary=false printer-location printer-make-and-model='HP Color LaserJet cp2025dn pcl3, hpcups 3.18.7' printer-state=3 printer-state-change-time=1553023232 printer-state-reasons=none printer-type=167964 printer-uri-supported=ipp://localhost/printers/Color-LaserJet-CP2025dn sides=one-sided
$ lpinfo -v network ipp network https network socket network beh direct hp network lpd file cups-brf:/ network ipps network http direct hpfax network dnssd://HP%20Color%20LaserJet%20CP2025dn%20(F47468)._pdl-datastream._tcp.local/ 

Команда lpoptions покажет настройки вашего принтера по умолчанию. Используйте параметр -p, чтобы указать один из нескольких доступных принтеров.

Команда lpstat -p отображает состояние принтера, а команда lpstat -p -d также выводит список доступных принтеров.

$ lpstat -p -d
printer Color-LaserJet-CP2025dn is idle. enabled since Tue 19 Mar 2019 05:07:45 PM EDT
system default destination: Color-LaserJet-CP2025dn

Чтобы распечатать документ на принтере по умолчанию, просто используйте команду lp, а затем имя файла, который вы хотите распечатать. Если имя файла содержит пробелы (что редко встречается в системах Linux), либо поместите имя в кавычки, либо начните вводить имя файла и нажмите клавишу табуляции, чтобы вызвать завершение файла (как показано во втором примере ниже).

$ lp "never leave home angry" $ lp never\ leave\ home\ angry
$ lpq Color-LaserJet-CP2025dn is ready and printing Rank Owner Job File(s) Total Size active shs 234 agenda 2048 bytes

Чтобы отменить задание на печать, вы можете использовать команду cancel или lprm. Если вы не будете действовать быстро, то можете увидеть это:

$ cancel 229 cancel: cancel-job failed: Job #229 is already completed - can't cancel.

Чтобы печатать в двухстороннем режиме, вы можете ввести команду lp с параметром sides, в котором указано, как печатать на обеих сторонах листа, и вид переплета (сбоку или сверху). Этот параметр представляет обычный способ, при которым вы получите двусторонний документ в портретном режиме.

$ lp -o sides=two-sided-long-edge Notes.pdf

Если вы хотите, чтобы все ваши документы печатались в двухстороннем режиме, вы можете изменить настройки lp для sides с помощью команды lpoptions.

$ lpoptions -o sides=two-sided-short-edge
$ lpoptions -o sides=one-sided
$ lp -o landscape penguin.jpg

Система печати, используемая в системах Linux, - это основанная на стандартах система печати с открытым исходным кодом, называемая CUPS, первоначально обозначавшая Common Unix Printing System. Она позволяет компьютеру выступать в качестве сервера печати.

Источник

How to Print files in Linux Using Command Line

Printing a file is one of the basic functionalities provide by the linux operating system, rather than just printing a file its provides us with a variety of options like to reformat it to adjust the margins, highlight some words, change text orientation and more. Undoubtedly we can print a file directly without passing any extra parameters but that would lead to a less appealing print, so here we see how to print a file and add optional parameters to make it look even better.

How to Print using pr command?

pr command is used as a basic command to print files, it has following syntax –

pr command does minor formatting to the input file you want to print by supplying options into the pr command, also pr command displays the file to user before printing it.

Here are the other options you can provide along with the pr command –

App Name Cheating Engine
Platform Android
Android Version Supported Android 4.1.1 or above
APK Size 1.5 MB
Android Version 6.5.2
Developer Francesco Guagnano

Printing file where k=2, to print the output in 2 columns –

How to Print using lp/lpr command?

Unlike pr command, lp/lpr can be directly used to print out onto the printer without displaying the file on user’s terminal. Once you are ready with formatting using the pr command, you can use any of these commands to print your file on the printer connected to your computer.

To use lp command make sure you set the default printer, the lp command shows an ID that you can use to cancel the print job or check its status.

  • If you are using the lp command, you can use the -nNum option to print Num numberof copies. Along with the command lpr, you can use -Num for the same.
  • If there are multiple printers connected with the shared network, then you can choose a printer using -dprinter option along with lp command and for the same purpose you can use -Pprinter option along with lpr command. Here printer is the printer name.

Check and Abort file printing using lpstat and cancel command

lpstat command can be used to get a view of the printer’s queue, they may include – request IDs, owners, file sizes, when the jobs were sent for printing, and the status of the requests. We can use lpstat -o to see all output requests

The cancel command terminates a printing request from the lp command. The lprm command terminates all lpr requests. You can specify either the ID of the request (displayed by lp or lpq) or the name of the printer, to cancel whatever request is currently printing, regardless of its ID, simply enter cancel and the printer name –

Along with following commands there are even more commands like lpq (similar to lpstat) , lprm (command will cancel the active printing job if it belongs to you), etc.

Источник

Оцените статью
Adblock
detector