Computing and the Command Line

nano: Quick Edits

nano is the friendly terminal editor installed on Ubuntu: open a file, type, Ctrl-O to save, Ctrl-X to quit. Read the help bar (^ is Ctrl, M- is Alt), search and replace, cut and paste lines, undo, jump to a line, and note that nano 8 moved search to Ctrl-F. Make it the editor other programs open, and set line numbers and sane tabs in ~/.nanorc.

  • 4 min
  • 6 steps
  • 2 questions
  • Lesson 19 of 80

In this lesson

  1. Opening, editing, saving
  2. The help bar
  3. Making nano your editor
  4. A .nanorc
  5. Your turn
  6. So

Opening, editing, saving

nano is a small, friendly editor that runs in the terminal, and it’s installed on Ubuntu out of the box 1. Open a file by name; if it doesn’t exist, nano creates it when you save:

me@linuxbox:~$ nano ~/.bash_aliases

Then just type. Arrow keys move the cursor, Backspace and Delete delete. To save, press Ctrl-O (“write Out”), check the file name it offers, and press Enter. To quit, Ctrl-X; if there are unsaved changes, nano asks whether to save them 2. Ctrl-S also saves, without asking 2.

To edit a system file, use sudoedit /etc/hosts (module 3); it opens your editor as you and saves the result as root.

A nano window editing /home/me/.bash_aliases, with a title bar, a few lines of aliases and a mkcd function, and the help bar at the bottom: ^G Help, ^O Write Out, ^F Where Is, ^K Cut, ^T Execute, ^C Location, ^X Exit, ^R Read File, ^\ Replace, ^U Paste, ^J Justify, ^/ Go To Line. A note says ^ means Ctrl and M- means Alt. Right, keys to know: Ctrl-O then Enter to save, Ctrl-S to save without questions, Ctrl-X to exit (it asks to save), Ctrl-F to search (older versions Ctrl-W), Ctrl-K to cut the line, Ctrl-U to paste, Alt-U to undo, Alt-N for line numbers, Ctrl-G for help. The help bar shows your version's keys.
nano tells you its keys. Read the bottom two lines. Credit: StudyCorner diagram · CC BY 4.0 · Source

The help bar

The two lines at the bottom of the screen are nano’s help bar. ^ means Ctrl, and M- means Alt (or press and release Esc first) 2. So ^X Exit is Ctrl-X, and M-U Undo is Alt-U. Ctrl-G opens the full help.

The keys you’ll use most 2:

Keys Does
Ctrl-O, Enter / Ctrl-S Save
Ctrl-X Exit
Ctrl-F, then Alt-F for the next match Search forward
Alt-R Search and replace
Ctrl-K Cut the current line (repeat to cut several)
Alt-6 Copy the current line
Ctrl-U Paste
Alt-U, Alt-E Undo, redo
Alt-G Go to a line number
Alt-N Show or hide line numbers
Ctrl-A, Ctrl-E Start, end of the line
Alt-A Start selecting text (then cut or copy the selection)

A version note. nano 8.0, released in May 2024, moved search to Ctrl-F (and backward search to Ctrl-B). Older versions, still common on long-term-support systems, search with Ctrl-W, “Where Is” 3. nano --version tells you which you have, and the help bar always shows the right keys for your copy.

Quick check

In nano’s help bar, what does ^X Exit mean?

Making nano your editor

Many programs open “your editor” for you: sudoedit, crontab -e, git commit, and others. They look at the VISUAL and EDITOR environment variables 1. Put these in ~/.profile (module 5):

export EDITOR=nano
export VISUAL=nano

On Debian and Ubuntu, sudo update-alternatives --config editor also sets the system-wide default for programs that don’t check those variables.

Quick check

How do you make programs like sudoedit and git open nano?

A .nanorc

nano reads settings from ~/.nanorc 2. A sensible start:

## line numbers down the left
set linenumbers
## new lines keep the previous line's indent
set autoindent
## Tab inserts four spaces
set tabsize 4
set tabstospaces
## click to move the cursor
set mouse

Comments go on their own lines, starting with #.

Syntax highlighting for shell scripts, config files, and many languages comes switched on in Ubuntu’s system-wide settings.

Your turn

Exercises

  1. Create ~/shell-course/shopping.txt in nano with five items, save it, and quit.
  2. Reopen it, move the third line to the top with cut and paste, undo that, then save without changes and quit.
  3. Use search and replace to change every “milk” to “oat milk.”
  4. Check your nano version, then create a ~/.nanorc with line numbers turned on. Reopen the file to see them.
  5. Add export EDITOR=nano and export VISUAL=nano to ~/.profile and load it with source ~/.profile.
Answers
  1. nano ~/shell-course/shopping.txt, type, Ctrl-O Enter, Ctrl-X.
  2. On line 3, Ctrl-K cuts it; move to line 1 and Ctrl-U pastes it; Alt-U undoes each step. If you undo back to the original, Ctrl-X exits without asking.
  3. Alt-R, type milk, Enter, type oat milk, Enter, then A for “All.”
  4. nano --version; echo "set linenumbers" >> ~/.nanorc.
  5. nano ~/.profile, add the two lines at the end, save, then source ~/.profile and echo $EDITOR.

So

nano is the quick way to edit a file in the terminal: type, Ctrl-O to save, Ctrl-X to leave. The help bar shows the keys (^ is Ctrl, M- is Alt), search is Ctrl-F in nano 8 and Ctrl-W before that, and EDITOR and ~/.nanorc make it yours.

Lesson complete

Nice work.

1day streak
0/1today's goal
–correct

Up next · 5 min

vim Essentials

Next lesson
Sources for this lesson
  1. 1
    William Shotts. The Linux Command Line, Seventh Internet Edition (25.12A). LinuxCommand.org (print edition by No Starch Press). 2026. verifiedFree CC BY-NC-ND 3.0 book, release 25.12A of July 18, 2026. Part 1, Learning the Shell: the shell and terminal emulators, prompts ($ vs. # for the superuser), command history (most distributions keep the last 1,000 commands), Shift-Ctrl-C/V for copy and paste; navigation and the directory tree; exploring the system (ls options and the long listing, file, less, the guided tour of /, symbolic links); manipulating files (wildcards and character classes, mkdir, cp, mv, rm, ln; no undelete, test wildcards with ls first); working with commands (four kinds of commands, type, which, help, --help, man and its sections, apropos, whatis, info, alias); redirection; expansion and quoting; Readline keyboard tricks, completion, history search; permissions; processes. Later parts cover the environment, vi, packages, storage, networking, find, archiving, regular expressions, text processing, and shell scripting.
  2. 2
    Cheatsheet for GNU nano. GNU nano project. verifiedCurrent nano keystrokes. File handling: Ctrl+S save, Ctrl+O save as, Ctrl+R insert a file, Ctrl+X close and exit. Editing: Ctrl+K cut line, Alt+6 copy line, Ctrl+U paste, Alt+U undo, Alt+E redo, Alt+3 comment. Search: Ctrl+F forward, Ctrl+B backward, Alt+F/Alt+B next, Alt+R replace. Moving: Ctrl+A/Ctrl+E line start/end, Alt+G go to line, Ctrl+Y/Ctrl+V page. Alt+N line numbers, Alt+A set mark, Ctrl+G help. Settings live in ~/.nanorc.
  3. 3
    GNU nano News. GNU nano project. verifiedGNU nano 8.0 'Grus grus' (May 1, 2024): ^F is bound by default to starting a forward search and ^B to a backward search, with M-F and M-B repeating it; the old bindings can be restored; --modernbindings gives ^Q quit, ^C copy, ^V paste, ^Z undo. Latest version 9.2 (July 31, 2026).