Nano is a simple yet powerful command-line text editor that comes pre-installed on most Linux distributions. It offers an intuitive interface and a wide range of features, making it an excellent choice for both beginners and experienced users.
In this comprehensive guide, we’ll explore how to use the Nano text editor effectively in Linux.
Table of Contents
Basic shortcuts for nano
Nano being a terminal-based editor, offers a variety of shortcuts here are some important shortcuts which will help you kick-start the editing process with Nano:
| Shortcut | Description |
|---|---|
Ctrl + G | Display help text. |
Ctrl + O | Save the current file. |
Ctrl + X | Exit Nano. |
Ctrl + W | Search for a string. |
Ctrl + K | Cut the current line. |
Ctrl + U | Paste the cut text. |
Ctrl + J | Justify the current paragraph. |
Ctrl + C | Display the current cursor position/ |
Ctrl + _ | Go to a specific line and column. |
Alt + A | Select text. |
Alt + 6 | Copy the selected text. |
Alt + U | Undo the last action. |
Alt + E | Redo the last undone action. |
I’ve only mentioned the basic shortcuts in the table. If you want to know more shortcuts, open the nano editor by typing nano in the terminal and press Ctrl + G. It will open the help section where you can find more shortcuts:

Now, let’s take a look at some basics of using the nano editor.
How to create and open files
To open an existing file with the nano editor, all you have to do is append the filename to the nano command followed by space as shown here:
nano Filename If I want to open the Hello.txt file, then I will use the following:
nano Hello.txt 
If the file is located in a different directory, then you need to append the path to the file to the nano command:
nano /path/to/file But how do you create files? The process is the same. When you try opening a file using the nano editor if it does not find any file with the given filename, then it will create a new file with the given filename.
For example, if I want to create a file named Kabir.txt, then all I have to do is execute the following command:
nano Kabir.txt 
How to copy and paste
As there’s no way to delete lines in the nano editor, you can refer to any of the two methods to cut lines to have similar effect to deleting lines.
There are two ways you can copy and paste into the nano editor:
- Using mouse (easy)
- Using keyboard shortcut
1. Copy and paste using a mouse
If you’re new to the terminal, then using keyboard shortcuts might be overwhelming for you and in that case, you can use a mouse to simplify the process.
To copy and paste, all you have to do is follow two simple steps:
- Select text using the mouse
- Right-click and select the
copyoption. Alternatively, you can press Ctrl + Shift + C to copy selected text using the mouse. - Use your keyboard’s arrow keys to move the cursor to where you want to paste text.
- Right-click and select the
pasteoption. Alternatively, you can pressCtrl + Shift + Vto paste copied text.
Looks confusing? Here’s a simple animation explaining all the steps at once:

2. Copy and paste using the keyboard
There’s one limitation of using a mouse to copy and paste in the nano editor – you can not copy anything beyond the visible screen. This means you can not select lines which are below the visible lines.
This method allows you to mark a point from where you can select text and use the nano shortcuts to copy and paste text. Here are the steps that you need to follow:
- Use the arrow keys from where you want to start the selection and press
Alt + Ato set a marker. - Now, use the arrow keys to select text.
- Press
Alt + 6to copy the selected area - Navigate to a line where you want to paste the text and then, press
Ctrl + Uto paste the copied text.
Sounds confusing? Here’s how to do it:

How to cut and paste
Like copying and pasting text, there are two ways you can cut and paste text in the nano editor:
- Cut and paste the entire line
- Cut and paste selected text
Both methods use keyboard shortcuts as you can not cut text using the mouse.
1. Cut and paste the entire line
I personally use this method as I often cut multiple lines from files and it is quite easy compared to the other (I’m about to show you in a moment). To cut and paste the entire line, you’d have to follow the given steps:
- Use arrow keys to navigate to the line which you want to cut and press
Ctrl + Kto cut the line. - Again use the arrow keys to navigate to where you want to paste the line and press
Ctrl + U.
Sounds complex? Here’s how you do it:

2. Cut and paste specific part
The previous method is only useful when you want to cut the entire line but what if you want to cut a specific part of the file? Well, in GUI editors, you can select the portion using a mouse and cut it but here, you have to use keyboard shortcuts.
To cut and paste a specific portion of the file, refer to the following steps:
- Navigate to the part of the file from where you want to select the text and press
Alt + Ato set a marker. - Now, use the arrow keys to select text.
- Press the
Ctrl + Kto cut the selected text. - Navigate to the line where you want to paste the text and press
Ctrl + Uto paste the text.
In case, you are still confused, here’s how I did it:

How to undo and redo
While editing, undoing and redoing are some of the most frequent actions a user will perform. Like any text editor, Nano also supports undoing and redoing actions.
To undo and redo in nano, you will have to use the given shortcuts:
| Action | Linux/Unix Shortcut | macOS Shortcut |
|---|---|---|
| Undo | Alt + U | Option + U |
| Redo | Alt + E | Option + E |
When you undo the operation, it will notify you saying “Undid <operation>” so if you undid the deletion, then it will read like “Undid deletion” as shown here:

When you redo the operation, it will notify you saying “Redid <operation>”. For example, if you deleted text and then redid the action, then, it will show “Redid deletion” as shown here:

How to search and replace
If you want to search and replace in the nano editor, it can be done in three easy steps:
- Press
Ctrl + \orAlt + rto launch the search and replace prompt. - Enter the term you want to search and then press the
Enterkey. - Here you will have two choices: either press
Ato replace all the found results or keep on pressingNkey till you find the target match and pressYto replace it.
Here, I will show you how you can replace all at once and replace selective terms.
1. Search and replace selective terms
When you search for a term, it will highlight all the matching results and you might not want to replace all the results. In that case, you can replace specific terms using the shown steps:
- First, press
Ctrl + \orAlt + rto launch the search and replace prompt and enter the term you want to search: - Enter the term you want to replace with:
- It will show you multiple search results. To ignore the highlighted search result, press
N: - Once you find the target keyword, press
Yfor one or more results and it will replace the keywords (I replaced two keywords here):
Still, looks confusing? Here’s a simple animation showing all the steps I performed to replace two terms:

2. Search and replace all the results
To search and replace all the terms in the file, all you have to do is refer to the following steps:
- Press
Ctrl + \orAlt + rto launch the search and replace prompt and enter the term you want to search (and later be replaced): - Enter the term you want to replace with:
- Press the
Akey to replace all the search results at once. In my case, it replaced all 4 terms at once:
Here’s a summary of all 3 steps in the form of animation:

How to save and exit
After making changes to the file, the last step is to save changes and exit from the nano editor. And trust me, it is relatively easy compared to doing the same on Vim.
To save and exit from the nano editor, follow the given steps:
- Press
Ctrl+sto save changes in the current file - Press
Ctrl + Oand then press theEnterkey (also allows you to save files with different names) - Press
Ctrl + Xto exit from the nano editor.
Here’s a detailed explanation of how you can save and exit from the nano editor.
1. Save the file in the nano editor (without exiting)
The easiest way to save file in the nano editor is to press
Ctrl + sas it won’t prompt you for any options or confirmation and write changes to the current file.
To save the file, press Ctrl + O and it will ask you to verify the filename as you can save changes by the different filenames also. If you just want to save the file, then verify the filename and hit the Enter key:

That’s it! Once you save changes, it will show you the number of lines written to the file:

2. Exit from the nano editor
To quit the nano editor, press Ctrl + X key.
If you didn’t save the changes you made, it will prompt you to ask if you want to save changes before exiting the nano editor. Press Y to save changes and N to not to:

If you press Y, then it will ask you to enter the filename to write changes. Simply press the Enter key and it will save changes.
That’s it!
Conclusion
In this tutorial, I went through all the basics you need to get started with the nano editor starting from crating to saving and exiting the nano editor.
I hope you will find this guide helpful and if you have any queries, leave us a comment.














