Nano is a simple, command-line text editor in Ubuntu and other Linux distributions. It is especially useful for quick edits and configurations directly in the terminal.
Opening a File
To open a file with Nano, use the following command:
nano <filename>
Example:
nano /etc/hosts
If the file doesn't exist, Nano will create it for you when you save.
Basic Commands in Nano
Once you're inside Nano, the basic commands are displayed at the bottom of the screen. Here are the key ones you need to know:
Move Cursor: Use arrow keys to move the cursor.
Write (Save) File:
Press Ctrl + O (then hit Enter to confirm).
Exit Nano:
Press Ctrl + X.
Cut (Delete) a Line:
Press Ctrl + K.
Paste a Line:
Press Ctrl + U.
Search for Text:
Press Ctrl + W and enter the search term.
Advanced Commands
Go to Line/Column:
Press Ctrl + _ and enter the line number.
Copy Text:
Set a starting mark with Ctrl + ^, then move the cursor and select the text to be copied. Finally, press Ctrl + K to cut it (or copy it).
Undo/Redo (if supported):
Press Alt + U to undo.
Press Alt + E to redo.
Exit Without Saving
If you've made changes but don't want to save:
Press Ctrl + X to exit.
When prompted to save changes, press N to discard the changes.
Search and Replace
Search: Press Ctrl + W, then type in the search string and hit Enter.
Replace: Press Ctrl + \, enter the search string, and follow the prompts to replace the text.
Useful Tips
Nano displays commands as ^ for Ctrl and M- for Alt. For example, ^X means Ctrl + X.
Enable Line Numbers: You can start nano with line numbers by running:
Getting Started with Nano
Nano is a simple, command-line text editor in Ubuntu and other Linux distributions. It is especially useful for quick edits and configurations directly in the terminal.
Opening a File
To open a file with Nano, use the following command:
Example:
If the file doesn't exist, Nano will create it for you when you save.
Basic Commands in Nano
Once you're inside Nano, the basic commands are displayed at the bottom of the screen. Here are the key ones you need to know:
Ctrl + O
(then hitEnter
to confirm).Ctrl + X
.Ctrl + K
.Ctrl + U
.Ctrl + W
and enter the search term.Advanced Commands
Ctrl + _
and enter the line number.Ctrl + ^
, then move the cursor and select the text to be copied. Finally, pressCtrl + K
to cut it (or copy it).Alt + U
to undo.Alt + E
to redo.Exit Without Saving
If you've made changes but don't want to save:
Ctrl + X
to exit.Search and Replace
Ctrl + W
, then type in the search string and hitEnter
.Ctrl + \
, enter the search string, and follow the prompts to replace the text.Useful Tips
^
forCtrl
andM-
forAlt
. For example,^X
meansCtrl + X
.