Linux Commands Examples

A great documentation place for Linux commands


Nano’s ANOther editor, an enhanced free Pico clone



add an example, a script, a trick and tips

: email address (won't be displayed)
: name

Step 2

Thanks for this example ! - It will be moderated and published shortly.

Feel free to post other examples
Oops ! There is a tiny cockup. A damn 404 cockup. Please contact the loosy team who maintains and develops this wonderful site by clicking in the mighty feedback button on the side of the page. Say what happened. Thanks!



Nano syntax highlighting malformed regex?

In general, you could do the "divide and conquer" route. Make a copy of the file. Remove half, try the config. If the syntax has an error, it's in the half that's in the file - repeat (remove half). If not, it's in the half that you deleted. Use the half that you split out, and remove half from that, until you get to one line that's bad.

I don't know the file format, but my guess would be the line

#color red ""(\\.|[^\"])*""

It starts with ", then a " right away, closing it, then regex in between. Im guessing you need to escape the inner quotes:

#color red "\"(\\.|[^\"])*\""
sudo nano $1

How do I select all text from a file with nano?

Have you tried this:

It isn't within nano, but you could cat the file into xclip with: cat test.txt | xclip


Open a Console Based Editor with limited access

Not exactly what you're looking for, but rvim does some of what you want. Perhaps it's possible to do some tricks with chroot. I don't know.

It will not be possible to start shell commands, or suspend Vim.


An esay way to empty a config file in Linux?

cat /dev/null > file.txt 

Executing this command will make the file blank.


Missing the first character of a line on full screen apps on Linux server ssh'ed from OS X Terminal

The problem you describe is typical of an incorrect value for the TERM environment variable. Specifically, the value of the TERM variable on Ubuntu selects a set of terminal features and capabilities that do not match those of the OS X Terminal application.

If TERM is set to something like xterm-color or xterm-256color try setting it to other values (e.g. the other one from the two I mentioned, or plain xterm, ansi or vt220).


In OS X, try the following commands

TERM=ansi nano googlef916dafa821844e0.html
TERM=vt220 nano googlef916dafa821844e0.html
TERM=xterm nano googlef916dafa821844e0.html
TERM=xterm-color nano googlef916dafa821844e0.html    
TERM=xterm-256color nano googlef916dafa821844e0.html

Find next command in nano?

You can get a list of all keyboard shortcuts by pressing ^G (Ctrl + G).

From Main nano help text:

M-W     (F16)           Repeat last search

M-W is Vim/Emacs notation, where M means Meta (a key present on MIT and Sun keyboards).

On IBM-compatible keyboards – depending on, e.g., your window manager and terminal emulator – you can invoke the shortcut with Alt + W (hold, tap), Win + W (hold, tap) or Esc, W (tap, tap).

In the unlikely case your keyboard has such a key, you can simply press F16.


Is it possible to remove the $ from nano in linux on longlines?

Yes this is possible. I no longer have nano installed so I can't lookup how. But you'll find the setting by doing either man nano or man nanorc.


Copying from one file to another using nano editor

Assuming you are in pure console mode and can't use the mouse to copy/paste:

  1. Launch nano in multi-buffer mode (nano -E)
  2. CTRL-^ to start your selection.
  3. Arrow key around until you cover all the text you want to copy.
  4. ESC-^ to copy the selection into the cut buffer
  5. CTRL-R ESC-F to open a file into a new buffer
  6. CTRL-U to paste in the opened file

NOTE: To switch between buffers use ESC-< and ESC->

An alternative to 2-4 above is to go to the line(s) you want to copy and CTRL-K to delete them, pressing CTRL-K repeatedly to multiple lines to the buffer. When you've cut all the lines you want to copy, CTRL-Y to re-paste them back into the current buffer. Then continue with step 5.


Nano-like editor that support Ctrl+Backspace and Ctrl+Arrow keys

I'm not sure if it's available in your environment, but a useful piece of software for the terminal is Midnight Commander (their site uses a self-signed certificate, so don't worry about this). It has a built-in editor with a lot of shortcuts, syntax highlighting, etc. and its behaviour is like in Windows.


Is there a way to make Nano support auto-complete and auto-bracket closing?

I just downloaded and perused the source of Nano with some grepping. I can say with 95% confidence that Nano doesn't support auto-bracket or auto-complete.

Meta-] will jump to the matching bracket under the cursor though.



Making nano accepting previous piped output as a file path

Nano behaves like expected, since a pipe is used to connect on program's output to another one's input.

What you want instead is to use the output of find as an argument for nano:

nano `find / -iname httpd.conf`

Nano usablely open second file

No, it's not possible. That's what advanced editors (Emacs, Vim, kate gedit, you name it) are for.

However, it is possible to do something useful, even though more restricted: you can add files to the one you are working on, and you can do so in a moderately effective way. When you say Read (or Write!) file, you may give the command ^T which will open a graphical window, and you can search for the file by moving within this graphical windows as if you were inside Nautilus or Dolphin, or whatever. Alternatively, again after invoking the Read or Write commands, you may issue commands to the shell by means of ^X.


Print feature in nano?

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:

   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:

   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.

How to save module configuration in Linux Terminal

In nano use "WriteOut" (CtrlO) to save the file.


This manual page briefly documents the nano command.

nano is a small, free and friendly editor which aims to replace Pico, the default editor included in the non-free Pine package. Rather than just copying Pico’s look and feel, nano also implements some missing (or disabled by default) features in Pico, such as "search and replace" and "go to line and column number".



Places cursor at line number LINE and column number COLUMN (at least one of which must be specified) on startup, instead of the default of line 1, column 1.


Same as -h (--help).

-A (--smarthome)

Make the Home key smarter. When Home is pressed anywhere but at the very beginning of non-whitespace characters on a line, the cursor will jump to that beginning (either forwards or backwards). If the cursor is already at that position, it will jump to the true beginning of the line.

-B (--backup)

When saving a file, back up the previous version of it to the current filename suffixed with a ~.

-C dir (--backupdir=dir)

Set the directory where nano puts unique backup files if file backups are enabled.

-D (--boldtext)

Use bold text instead of reverse video text.

-E (--tabstospaces)

Convert typed tabs to spaces.

-F (--multibuffer)

Enable multiple file buffers, if available.

-H (--historylog)

Log search and replace strings to ~/.nano_history, so they can be retrieved in later sessions, if nanorc support is available.

-I (--ignorercfiles)

Don’t look at SYSCONFDIR/nanorc or ~/.nanorc, if nanorc support is available.

-K (--rebindkeypad)

Interpret the numeric keypad keys so that they all work properly. You should only need to use this option if they don’t, as mouse support won’t work properly with this option enabled.

-L (--nonewlines)

Don’t add newlines to the ends of files.

-N (--noconvert)

Disable automatic conversion of files from DOS/Mac format.

-O (--morespace)

Use the blank line below the titlebar as extra editing space.

-Q str (--quotestr=str)

Set the quoting string for justifying. The default is "^([ \t]*[#:>\|}])+" if extended regular expression support is available, or "" otherwise. Note that \t stands for a Tab.

-R (--restricted)

Restricted mode: don’t read or write to any file not specified on the command line; read any nanorc files; allow suspending; allow a file to be appended to, prepended to, or saved under a different name if it already has one; or use backup files or spell checking. Also accessible by invoking nano with any name beginning with ’r’ (e.g. "rnano").

-S (--smooth)

Enable smooth scrolling. Text will scroll line-by-line, instead of the usual chunk-by-chunk behavior.

-T cols (--tabsize=cols)

Set the size (width) of a tab to cols columns. The value of cols must be greater than 0. The default value is 8.

-U (--quickblank)

Do quick statusbar blanking. Statusbar messages will disappear after 1 keystroke instead of 25. Note that -c overrides this.

-V (--version)

Show the current version number and exit.

-W (--wordbounds)

Detect word boundaries more accurately by treating punctuation characters as part of a word.

-Y str (--syntax=str)

Specify a specific syntax highlighting from the nanorc to use, if available.

-c (--const)

Constantly show the cursor position. Note that this overrides -U.

-d (--rebinddelete)

Interpret the Delete key differently so that both Backspace and Delete work properly. You should only need to use this option if Backspace acts like Delete on your system.

-h (--help)

Show a summary of command line options and exit.

-i (--autoindent)

Indent new lines to the previous line’s indentation. Useful when editing source code.

-k (--cut)

Enable cut from cursor to end of line.

-l (--nofollow)

If the file being edited is a symbolic link, replace the link with a new file instead of following it. Good for editing files in /tmp, perhaps?

-m (--mouse)

Enable mouse support, if available for your system. When enabled, mouse clicks can be used to place the cursor, set the mark (with a double click), and execute shortcuts. The mouse will work in the X Window System, and on the console when gpm is running.

-o dir (--operatingdir=dir)

Set operating directory. Makes nano set up something similar to a chroot.

-p (--preserve)

Preserve the XON and XOFF sequences (^Q and ^S) so they will be caught by the terminal.

-q (--quiet)

Do not report errors in the nanorc file and ask them to be acknowledged by pressing Enter at startup.

-r cols (--fill=cols)

Wrap lines at column cols. If this value is 0 or less, wrapping will occur at the width of the screen less cols columns, allowing the wrap point to vary along with the width of the screen if the screen is resized. The default value is -8.

-s prog (--speller=prog)

Enable alternative spell checker command.

-t (--tempfile)

Always save changed buffer without prompting. Same as Pico’s -t option.

-u (--undo)

Enable experimental generic-purpose undo code. By default, the undo and redo shortcuts are Meta-U and Meta-E, respectively.

-v (--view)

View file (read only) mode.

-w (--nowrap)

Disable wrapping of long lines.

-x (--nohelp)

Disable help screen at bottom of editor.

-z (--suspend)

Enable suspend ability.

-$ (--softwrap)

Enable ’soft wrapping’. nano will attempt to display the entire contents of a line, even if it is longer than the screen width. Since ’$’ normally refers to a variable in the Unix shell, you should specify this option last when using other options (e.g. ’nano -wS$’) or pass it separately (e.g. ’nano -wS -$’).

-a, -b, -e, -f, -g, -j

Ignored, for compatibility with Pico.


initialization file

nano will read initialization files in the following order: SYSCONFDIR/nanorc, then ~/.nanorc. Please see nanorc(5) and the example file nanorc.sample, both of which should be provided with nano.


If no alternative spell checker command is specified on the command line or in one of the nanorc files, nano will check the SPELL environment variable for one.

In some cases nano will try to dump the buffer into an emergency file. This will happen mainly if nano receives a SIGHUP or SIGTERM or runs out of memory. It will write the buffer into a file named if the buffer didn’t have a name already, or will add a ".save" suffix to the current filename. If an emergency file with that name already exists in the current directory, it will add ".save" plus a number (e.g. ".save.1") to the current filename in order to make it unique. In multibuffer mode, nano will write all the open buffers to their respective emergency files.


Please send any comments or bug reports to

The nano mailing list is available from nano-devel[:at:]gnu[:dot:]org.

To subscribe, email to nano-devel-request[:at:]gnu[:dot:]org with a subject of "subscribe".

see also

(or equivalent on your system)


Chris Allegretta <chrisa[:at:]asty[:dot:]org>, et al (see AUTHORS and THANKS for details). This manual page was originally written by Jordi Mallach <jordi[:at:]gnu[:dot:]org>, for the Debian system (but may be used by others).

How can this site be more helpful to YOU ?

give  feedback