nanoEdit files with nano, the beginner-friendly editor
nano is a small, modeless terminal editor: you type and the text goes in, and the key shortcuts are listed at the bottom of the screen. It's Ubuntu's default editor for crontab -e, visudo and git, and the quickest safe way to make a small config change when you don't know vim.
nano [OPTIONS] [+LINE[,COLUMN]] FILE...You need to change one setting in a server config and you're not comfortable with vim.
sudoNeeded to save a root-owned file. sudoedit is the safer alternative: you edit a copy as yourself.
nano reads the file into memory and draws it with the curses library: a title bar (version, file name, and * when modified), the text, a status line for messages and prompts, and two lines of shortcuts. ^ means Ctrl and M- means Alt (or Esc then the key). Because there are no modes, every printable key inserts text; commands are always Ctrl or Alt combinations, which is why it's easier for beginners than vim. On ^O (Write Out) nano writes the buffer to the file, overwriting it in place so the inode, owner and permissions stay the same. With locking on (Ubuntu's /etc/nanorc sets it), nano creates a lock file (.name.swp, in vim's format), so a second nano or vim on the same file is warned. If the file isn't writable, nano says so on opening and the save fails with Permission denied. Many tools start the editor named in $VISUAL or $EDITOR, falling back to the system's editor alternative, which on Ubuntu is nano.
^O then EnterWrite Out (save) to the file name shown^SSave immediately, without the file-name prompt^XExit; asks Save modified buffer? Y/N if changed^W / ^\Search (Where Is) / search and replace^K / ^UCut the current line / paste (uncut)^/ or ^_Go to line (and column)M-U / M-EUndo / redo^CShow cursor position (line, column)-lShow line numbers+NOpen at line N-vView mode: read-only-BKeep a backup of the original as file~ when savingPressing Ctrl+Z to undo out of habitnano 7 answers '[ To suspend, type ^T^Z ]' and undoes nothing; older versions suspend the editor to the background, which looks like it vanished (fg brings it back).
M-U (Alt+U) to undo, M-E to redo; ^S saves straight away, ^O saves with a file-name promptEditing a YAML or Python file with nano's default tab settingsTab inserts a literal tab character, which YAML rejects and Python may mix with spaces.
nano -E (convert tabs to spaces) with -T 2, or set tabstospaces in ~/.nanorcsudo nano /etc/sudoersA single typo makes sudoers unparsable, and then nobody can use sudo to fix it.
sudo visudo (opens nano on Ubuntu, but checks the syntax before installing the file)Try these on a Linux machine of your own. Each task has a hint and a solution.
Open ~/data/notes.txt in nano with line numbers, add a line 'Checked by devops' at the end, save and exit.
Open /etc/app/app.conf at line 9 and find the word 'level' without moving the cursor manually.
Change maintenance_mode=off to on in /etc/app/features.conf the safe way.
nanoEdit files with nano, the beginner-friendly editor
nano is a small, modeless terminal editor: you type and the text goes in, and the key shortcuts are listed at the bottom of the screen. It's Ubuntu's default editor for crontab -e, visudo and git, and the quickest safe way to make a small config change when you don't know vim.
nano [OPTIONS] [+LINE[,COLUMN]] FILE...You need to change one setting in a server config and you're not comfortable with vim.
sudoNeeded to save a root-owned file. sudoedit is the safer alternative: you edit a copy as yourself.
nano reads the file into memory and draws it with the curses library: a title bar (version, file name, and * when modified), the text, a status line for messages and prompts, and two lines of shortcuts. ^ means Ctrl and M- means Alt (or Esc then the key). Because there are no modes, every printable key inserts text; commands are always Ctrl or Alt combinations, which is why it's easier for beginners than vim. On ^O (Write Out) nano writes the buffer to the file, overwriting it in place so the inode, owner and permissions stay the same. With locking on (Ubuntu's /etc/nanorc sets it), nano creates a lock file (.name.swp, in vim's format), so a second nano or vim on the same file is warned. If the file isn't writable, nano says so on opening and the save fails with Permission denied. Many tools start the editor named in $VISUAL or $EDITOR, falling back to the system's editor alternative, which on Ubuntu is nano.
^O then EnterWrite Out (save) to the file name shown^SSave immediately, without the file-name prompt^XExit; asks Save modified buffer? Y/N if changed^W / ^\Search (Where Is) / search and replace^K / ^UCut the current line / paste (uncut)^/ or ^_Go to line (and column)M-U / M-EUndo / redo^CShow cursor position (line, column)-lShow line numbers+NOpen at line N-vView mode: read-only-BKeep a backup of the original as file~ when savingPressing Ctrl+Z to undo out of habitnano 7 answers '[ To suspend, type ^T^Z ]' and undoes nothing; older versions suspend the editor to the background, which looks like it vanished (fg brings it back).
M-U (Alt+U) to undo, M-E to redo; ^S saves straight away, ^O saves with a file-name promptEditing a YAML or Python file with nano's default tab settingsTab inserts a literal tab character, which YAML rejects and Python may mix with spaces.
nano -E (convert tabs to spaces) with -T 2, or set tabstospaces in ~/.nanorcsudo nano /etc/sudoersA single typo makes sudoers unparsable, and then nobody can use sudo to fix it.
sudo visudo (opens nano on Ubuntu, but checks the syntax before installing the file)Try these on a Linux machine of your own. Each task has a hint and a solution.
Open ~/data/notes.txt in nano with line numbers, add a line 'Checked by devops' at the end, save and exit.
Open /etc/app/app.conf at line 9 and find the word 'level' without moving the cursor manually.
Change maintenance_mode=off to on in /etc/app/features.conf the safe way.