How to Edit a File Using Nano in Ubuntu

The Text Manipulation Vector

When administering a headless Ubuntu Linux server, you will spend 90% of your time editing raw text files—tweaking firewall rules, configuring web server virtual hosts, or writing bash scripts. Because you do not have access to a graphical desktop, you cannot simply open Notepad or VS Code. You must utilize a terminal-based text editor that operates entirely within the constraints of the command line.

How to Edit a File Using Nano

While veterans prefer the immense power (and steep learning curve) of vim, the nano editor is universally recommended for standard users due to its intuitive, on-screen keyboard shortcut menu.

1. Open your terminal application or connect to your server via SSH.
2. To open a file (or create a new one if it doesn’t exist), type nano followed by the absolute path to the file. For example, to edit the primary network configuration file, you must execute the command with superuser privileges:

sudo nano /etc/network/interfaces

3. Your terminal interface will instantly transform. The content of the file will dominate the main screen, and a crucial menu bar will appear at the absolute bottom.
4. Navigation: Do not attempt to use your mouse to click where you want to type. You must use the Arrow Keys on your keyboard to physically move the blinking cursor to the desired line.
5. Editing: Once the cursor is in position, simply type your changes as if you were using a standard word processor.
6. Saving and Exiting (The Crucial Step):
* Look at the bottom menu. The ^ symbol represents the Ctrl key.
* To save your changes, press Ctrl + O (Write Out). Nano will ask you to confirm the filename at the bottom. Press Enter.
* To exit the editor and return to the bash prompt, press Ctrl + X (Exit).

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.