Use nano to Edit Files in Linux
Updated by Edward Angert Written by Edward Angert
GNU nano, or more commonly, nano is the basic, built-in editor for most Linux distributions. In this QuickAnswer, we’ll cover some of the essentials to help you get started.
To learn more, visit our full guide on using nano.
Use nano to Open a System File
From the terminal, enter
nano and the file name. If the file doesn’t exist, nano will create a new, temporary version in the location you specify. In this example, we’ll use
sudo permissions to open the system’s hosts file:
sudo nano /etc/hosts
The above example opens the system hosts file, similar to the following:
In the default view, nano displays the file being edited in the center of the top Titlebar. At the bottom, the Shortcut List shows commonly used commands where
^ stands for the CTRL key. To save, hold CTRL and press O (for Write *O*ut); to exit, CTRL+X.
Notice that some commands induce the Statusbar, at the bottom, directly above the Shortcut List. For example, the Statusbar appears when saving files and running searches (CTRL+W).
Helpful nano Shortcuts
- ^W: Search within the open file
- ALT+W: Find the next instance of the search
- ^O: Save the file
- ^K: Cut the entire line
- ^U: Paste the entire line
- ^T: View the file browser
- ^X: Exit
You may wish to consult the following resources for additional information on this topic. While these are provided in the hope that they will be useful, please note that we cannot vouch for the accuracy or timeliness of externally hosted materials.
Join our Community
This guide is published under a CC BY-ND 4.0 license.