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?

2 Answers 2

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.
2
  • 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
    Commented Sep 29, 2013 at 14:39
  • @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
    Commented Sep 29, 2013 at 14:52
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!
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
    Commented Dec 21, 2017 at 8:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .