8

I would like to use a Linux distro without a desktop environment, but I need to print out homework that I type up.

I could always email it to myself and print from another computer, but it would be nice if I could just do something like print homework.txt from a bash prompt. Does anyone have a way of doing this?

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
Broseph
  • 205
  • 1
  • 3
  • 6

3 Answers3

18

CUPS understands many different types of files directly, including text, PostScript, PDF, and image files. This allows you to print from inside your applications or at the command-line, whichever is most convenient! Type either of the following commands to print a file to the default (or only) printer on the system:

lp filename 
lpr filename

Use the -d option with the lp command to print to a specific printer:

lp -d printer filename

Or the -P option with the lpr command:

lpr -P printer filename

Printing the Output of a Program

Both the lp and lpr commands support printing from the standard input:

program | lp
program | lp -d printer
program | lpr
program | lpr -P printer

If the program does not provide any output, then nothing will be queued for printing.

More advanced options can be added to the print job with the -o options. For exampling stapling:

lpr -P printer -o StapleLocation=UpperLeft

Source and more Details.

Vasco
  • 105
  • 2
Nidal
  • 8,856
  • 11
  • 55
  • 74
5

Last time I was using such a system, I used to prefer enscript. It's been a while but I seem to recall it being a more sophisticated version of lpr which could do everything that lpr did and then some. It works like so:

enscript foo.file

It can either print directly to a printer or convert text to postscript. It should be available in the repositories of all major distributions.

terdon
  • 234,489
  • 66
  • 447
  • 667
0

Here's what worked for me:

I chose to install Manjaro "Full" which includes printer networking and printing support. From past experience, the "Minimal" install requires a non-trivial amount of effort to get anything printed.

I didn't know the name of my printer. I tried lpstat -t but that showed the following:

scheduler is running
no system default destination
lpstat: No destinations added.
lpstat: No destinations added.
lpstat: No destinations added.
lpstat: No destinations added.

At first, I was able to get lpstat working by connecting through Geany, but the printer would timeout after a few minutes.

Since I have a relatively new printer, it uses the "IPP" standard. I used ippfind -l thanks to this answer https://unix.stackexchange.com/a/490827/8234

For me the address was ipp://whatever.local:631/ipp/print

Then I found this answer https://unix.stackexchange.com/a/683993/8234 and that worked great lpadmin -p Cool -v ipp://whatever.local:631/ipp/print -m everywhere

Now lpstat -t works as expected:

Cool accepting requests since Sun 19 Mar 2023 02:23:37 AM CDT printer Cool is idle. enabled since Sun 19 Mar 2023 02:23:37 AM CDT

Then I can simply do echo "test" | lp -d Cool

PS: Perhaps there is an easier way. You can try ippfind -s and then change the spaces to underscores like echo "test" | lp -d Canon_Cool_series but I can't get this to work without the underscores, and I can't find any documentation explaining why this works. Basically, I cheated by activating the printer through Geany, and then I could see the printer with lpstat -t

For future reference, I would try the easier "underscore" method first, and if that times out or doesn't work, use the longer "lpadmin" method.

PJ Brunet
  • 733
  • 8
  • 17