nano
edit a file in the terminalnano is the editor to start with. You type and the text appears; the shortcuts are printed along the bottom of the screen. On a server with no desktop it is how configuration files get edited.
Ctrl+O saves, Ctrl+X exits — the caret in the on-screen help means the Ctrl key.
At the terminal
Read the session first, then the notes: each numbered line in the output is answered by the note with the same number.
What the numbered lines are telling you
The file being edited, and "Modified" once anything has changed that is not yet saved.
Type to insert; move with the arrow keys. There are no modes to switch between.
^ means Ctrl. "Write Out" is nano’s name for save, and "Where Is" for search.
Files under /etc belong to root. Without sudo, nano opens the file but cannot save it.
Switches
A switch changes how the command behaves. These are the ones used day to day; man nano lists the rest. Single-letter switches can usually be joined, so -l -a may be written -la.
-l- Show line numbers.
+NUM- Open with the cursor on line NUM.
-B- Keep a backup of the original file, with a ~ suffix.
-v- View only: open the file read-only.
-m- Enable the mouse for placing the cursor.
Variations worth knowing
The same tool, pointed at a narrower question. These four cover most of what it is reached for day to day.
nano +42 script.shOpens the file with the cursor on line 42.
nano -l config.ymlShows line numbers.
nano -B /etc/fstabKeeps a backup of the original, named with a trailing ~.
sudoedit /etc/hostsThe safer way to edit a root-owned file: your editor runs as you, on a copy.
In cybersecurity
Editing a system file is the moment a typing mistake becomes an outage.
sudo nano runs the whole editor as root, and an editor can run commands. sudoedit runs it as you and copies the result into place.
Never edit /etc/sudoers with a plain editor. visudo checks the syntax before saving, so a mistake cannot lock you out of sudo.
Editors leave copies such as config.php~ or .swp files. In a web root these can be downloaded as plain text, revealing passwords.