There’s no denying that, for new Linux users, using the terminal is pretty scary. Scarier still is the thought of editing files at the terminal, with editors like Vim and GNU Emacs proving to be difficult for beginners to get their head around. For example, even exiting Vim proves to be a difficult task for many.
Rather than overcomplicate matters, you can go back to basics with a simple Linux text editor: Nano. It has a lot of fans, thanks to the simplicity of its interface, the powerful keyboard shortcuts it includes, and popular features like searching and line numbering. This guide shows how to use it.
Opening Nano on Linux
Nano is pre-installed on most Linux distributions, so you shouldn’t need to install it. To run Nano, open a terminal and type simply:
This will open an empty file for you to begin writing to.
If you want to open a file, type:
Replace “/folder/filename” with the location of the file you’re looking to edit.
You can also do this with a file that doesn’t technically exist. Nano will create an empty file with that filename in the location you’ve provided.
Nano also allows you to open a file at a specific line or column. To do so, type the following:
Replace “line-number” and “column-number” with appropriate line and column numbers and “filename” with the filename for your text file. For instance:
Nano will open your chosen file at the location you’ve given, ready for you to begin editing.
Using Nano Keyboard Commands
As a terminal text editor, you can’t use your mouse to navigate the Nano app. You’ll need to use keyboard shortcuts to be able to open, save and close files at will.
Some of these are listed continuously at the bottom of the Nano window, but for reference, here are some of the more common commands you can use.
- Ctrl + G: Opens the Nano help menu.
- Ctrl + O: Saves your open file. Nano will ask you to confirm the file name when doing this, so just press Enter to confirm.
- Ctrl + C: Cancels any pending command.
- Ctrl + X: Exits Nano. This will also prompt you whether you want to save the file if you’ve made any changes to it. Press Enter to confirm if you do.
- Ctrl + W: Opens a search box. Type and enter into this to locate certain text.
- Ctrl + K: Deletes the current line of text.
- Ctrl + _ (underscore): Moves to a certain line number. Type the line number in and press the enter button to confirm.
- Ctrl + \ (backslash): Find and replace text. Type the text you’re looking to replace, then press Enter.
There are other commands you can try, which you can learn more about from the Nano help menu (Ctrl + G). One of the most useful additional nano commands is to check the spelling in your text. This requires you to install an extra package, so if you’re on a Debian or Ubuntu-based Linux distribution, open a terminal and type:
Once installed, open Nano and press Ctrl + T. This will begin spellchecking your document.
If it locates any text it believes is incorrect, it will prompt you to edit it. Make the change, then press Enter to save the change.
Editing Files from the Linux Terminal
Nano is simple, and once you’ve started using it, pretty easy to get your head around. While more advanced text editors offer better features, Nano stays true to what it does best – editing files with no fuss and no problem.
If you’ve outgrown Nano and are looking for a better alternative, you could try some of the best Linux text editors like Atom instead.
Our latest tutorials delivered straight to your inbox