Print feature in nano?

1

1

Is there a way to print a document from the nano text editor, i.e. send it to a printer to be physically printed out? I see that vim and emacs have this feature but I like the simplicity of nano. If not, is there a way to print the document with a linux command?

Neal

Posted 2013-09-29T10:15:24.977

Reputation: 11

Answers

1

I can see no mention of a print command in nano's manual and it would surprise me to find one. The traditional method of printing in *nix systems is the lpr command:

$ lpr foo.txt

From man lpr:

DESCRIPTION
   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.

You can also use a slightly more modern equivalent, enscript:

DESCRIPTION
   Enscript converts text files to PostScript  or  to  other  output  lan‐
   guages.   Enscript  can spool the generated output directly to a speci‐
   fied printer or leave it to a file.   If  no  input  files  are  given,
   enscript  processes the standard input stdin.  Enscript can be extended
   to handle different output media and it has many options which  can  be
   used to customize the printouts.

terdon

Posted 2013-09-29T10:15:24.977

Reputation: 45 216

Would this work for files with non .txt extensions? lpr will only print plaintext files but I need to print out source code for files with extensions like .cpp, but the contents are basically plaintext, aren't they? Thanks. – Neal – 2013-09-29T14:39:20.217

@Neal the *nix world does not use extensions not determine file type (some graphical apps do but those are another matter). lpr will treat its input as text and print it accordingly. – terdon – 2013-09-29T14:52:39.553

0

I needed to do the same thing. My solution using the command line:

  • Type less filename >> filename.txt.
  • Then I typed lp filename.txt and it printed!

Larry Johnson

Posted 2013-09-29T10:15:24.977

Reputation: 1

This command isn't actually using nano like the OP asked for, but it is a neat solution. Could you perhaps go into a little more detail on what lp does? – Burgi – 2017-12-21T08:57:05.537