How to use the nano command line editor in Linux

This article is designed to provide a few basic instructions for using the Linux nano command line editor. While nano does not offer the power of editors such as vi or vim, it works great for day to day editing where advanced features are not required.

Install nano

CentOS, Fedora, Redhat

sudo yum install nano

Ubuntu, Debian

sudo apt-get install nano


Start nano

nano /path/to/file/filename


Basic Editing

Using the nano editor is similar to most graphical editors you have used. Use the arrow keys to navigate the file, and type text as required. You can even use the Delete and Backspace buttons.

The keyboard is always in “insert” mode. You cannot de-select this to change to “over-strike” mode.


Keyboard shortcuts

Cancel: If you accidentally enter a command, you can cancel it anytime by pressing Ctrl+c to return to the editor.

Exit: Ctrl+x
If you have not saved your work, you will be promted to before exiting the program.

Save modified buffer (ANSWERING "No" WILL DESTROY CHANGES) ?

Press y to save or n to exit without saving.

Save: Ctrl+o
To continue using the current file name, simply press Enter
To save to a new file name, enter the new name, then press Enter

Search: Ctrl+w
Enter the text you are searching for and press Enter
To search for additional instances of the same text, simply press Ctrl+w again followed by Enter

Search and Replace: Ctrl+\ (backslash)
Type the text to search for and press Enter.
Next type the text you are going to replace it with, then press Enter.
Before any text is replaced, the program will highlight the next intance it finds of the text to replace and will prompt you with the following question:

Replace this instance?

Press y to replace the displayed instance and move to the next.
Press n to skip and move to the next instance.
Press a to replace all instances found in the file.

Author: admin on July 5, 2014
Category: Linux

Leave a Reply

You must be logged in to post a comment.

Last articles