Nano is a simple and beginner-friendly command-line text editor commonly used on Linux systems. It allows you to create and edit text files directly from the Terminal without needing a graphical text editor.
In this beginner guide, I will explain how to open Nano, create and edit files, save your work, search for text, cut and paste content, and use the most useful Nano keyboard shortcuts.
What Is Nano in Linux?
GNU Nano is a terminal-based text editor. It is especially useful when working on Linux servers, editing configuration files, writing scripts, or making quick changes to text files.
One reason Nano is beginner-friendly is that many of its main keyboard shortcuts are displayed at the bottom of the editor.
How to Open Nano
Open the Linux Terminal and type:
nano
Then press Enter.
Open Terminal, type nano and press Enter.
After pressing Enter, the Nano text editor will open inside the Terminal.
Nano text editor interface.
How to Open or Create a File with Nano
To edit an existing file or create a new one, type nano followed by the file name.
nano filename.txt
For example:
nano notes.txt
If notes.txt already exists, Nano will open it. If it does not exist,
Nano lets you create the file and save it.
Understanding Nano Keyboard Shortcuts
At the bottom of Nano you will normally see shortcuts such as ^O,
^X and ^W.
The ^ symbol represents the Ctrl key. For example:
- ^O means Ctrl + O
- ^X means Ctrl + X
- ^W means Ctrl + W
Most Useful Nano Commands
| Shortcut | Function |
|---|---|
| Ctrl + O | Save or write the current file |
| Ctrl + X | Exit Nano |
| Ctrl + G | Open Nano help |
| Ctrl + W | Search for text |
| Ctrl + K | Cut the current line or selected text |
| Ctrl + U | Paste or uncut text |
| Ctrl + A | Move to the beginning of the current line |
| Ctrl + E | Move to the end of the current line |
| Ctrl + P | Move to the previous line |
| Ctrl + N | Move to the next line |
| Ctrl + F | Move forward one character |
| Ctrl + B | Move backward one character |
| Ctrl + V | Move to the next screen |
| Ctrl + Y | Move to the previous screen |
| Ctrl + R | Read and insert another file |
| Ctrl + J | Justify the current paragraph |
| Ctrl + 6 | Start or stop selecting text |
| Ctrl + D | Delete the character under the cursor |
| Ctrl + H | Delete the character before the cursor |
| Ctrl + L | Refresh the Nano screen |
| Ctrl + C | Display the current cursor position |
| Ctrl + _ | Go to a specific line and column |
How to Save a File in Nano
After making changes, press:
Ctrl + O
Nano will display the file name near the bottom of the screen. Press Enter to confirm the name and save the file.
How to Exit Nano
To close Nano, press:
Ctrl + X
If the file contains unsaved changes, Nano may ask whether you want to save them.
- Press Y to save the changes.
- Press N to exit without saving.
How to Open Nano Help
Press:
Ctrl + G
Nano will display its built-in help screen containing additional commands and keyboard shortcuts.
How to Cut and Paste Text in Nano
To cut the current line or selected text, press:
Ctrl + K
To paste the text again, press:
Ctrl + U
How to Search for Text in Nano
Press:
Ctrl + W
Type the word or phrase you want to find and press Enter. Nano will move the cursor to the matching text.
How to Select Text in Nano
Move the cursor to where you want the selection to begin and press:
Ctrl + 6
Use the arrow keys to select the required text. You can then use Ctrl + K to cut the selected text.
Moving Around a File in Nano
Nano includes several useful navigation shortcuts:
- Ctrl + A – move to the start of the current line.
- Ctrl + E – move to the end of the current line.
- Ctrl + P – move to the previous line.
- Ctrl + N – move to the next line.
- Ctrl + F – move forward one character.
- Ctrl + B – move backward one character.
- Ctrl + V – move to the next screen.
- Ctrl + Y – move to the previous screen.
How to Go to a Specific Line in Nano
If you are editing a large file, you can jump directly to a particular line. Press:
Ctrl + _
Enter the line number, or line and column number, and press Enter.
How to Edit a Linux Configuration File with Nano
Nano is commonly used to edit Linux configuration files. Some system files require administrator privileges.
For example:
sudo nano /etc/hosts
After editing the file, use Ctrl + O to save it and Ctrl + X to exit.
Always be careful when changing system configuration files because incorrect changes can affect how your Linux system works.
Frequently Asked Questions About Nano
How do I save a file in Nano?
Press Ctrl + O, confirm the file name and press Enter.
How do I exit Nano?
Press Ctrl + X. If there are unsaved changes, Nano will ask whether you want to save them.
How do I exit Nano without saving?
Press Ctrl + X and then choose N when Nano asks whether you want to save the changes.
How do I search for a word in Nano?
Press Ctrl + W, enter the search text and press Enter.
How do I copy or move text in Nano?
Use Ctrl + 6 to begin selecting text, move the cursor to highlight it, use Ctrl + K to cut it, and Ctrl + U to paste it.
Is Nano suitable for beginners?
Yes. Nano is one of the easier command-line text editors to learn because many of its main shortcuts are displayed directly inside the editor.
Conclusion
Nano is a useful Linux text editor for beginners and experienced users who need to quickly edit files from the command line. The most important shortcuts to remember are Ctrl + O for saving, Ctrl + X for exiting, Ctrl + W for searching, Ctrl + K for cutting, and Ctrl + U for pasting.
Once you learn these basic commands, editing files through the Linux Terminal becomes much easier.
Related: Read my Ubuntu guide .
No comments:
Post a Comment