Vol. I · No. 46The command line sectionSat, 10 Oct 2026
Linux · reading files

nano

edit a file in the terminal

nano 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.

Save
Ctrl+O
then Enter to confirm the name
Exit
Ctrl+X
asks to save if changed
Search
Ctrl+W
Alt+W repeats
Cut and paste
Ctrl+K, Ctrl+U
a line at a time

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.

user@netflow — bashnano
$ nano notes.txt
1 GNU nano 7.2 notes.txt Modified
 
Buy a new switch for the lab
2Renew the domain before October
 
3^G Help ^O Write Out ^W Where Is ^K Cut ^T Execute
^X Exit ^R Read File ^\ Replace ^U Paste ^J Justify
4$ sudo nano /etc/hosts
Illustrative session · names, sizes and dates are examples, and every address is from a documentation or private range
Reading the output

What the numbered lines are telling you

1
The title bar

The file being edited, and "Modified" once anything has changed that is not yet saved.

2
The text area

Type to insert; move with the arrow keys. There are no modes to switch between.

3
The shortcut bar

^ means Ctrl. "Write Out" is nano’s name for save, and "Where Is" for search.

4
System files need root

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.sh

Opens the file with the cursor on line 42.

nano -l config.yml

Shows line numbers.

nano -B /etc/fstab

Keeps a backup of the original, named with a trailing ~.

sudoedit /etc/hosts

The 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.

Prefer sudoedit to sudo nano

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.

Use the right tool for sudoers

Never edit /etc/sudoers with a plain editor. visudo checks the syntax before saving, so a mistake cannot lock you out of sudo.

Backup files left behind

Editors leave copies such as config.php~ or .swp files. In a web root these can be downloaded as plain text, revealing passwords.

Filed under

Reading files

Read alongside