nano

Simple, user-friendly text editor for the terminal

Syntax

nano [options] [file]

Basic Usage

Open a file

nano filename.txt

Opens the specified file in nano editor.

Create a new file

nano

Open file with line numbers

nano -l filename.txt

Common Options

  • -B: Create backup files
  • -c: Constantly show cursor position
  • -i: Auto-indent new lines
  • -l: Show line numbers
  • -m: Enable mouse support
  • -r: Set line wrapping column
  • -s: Enable smooth scrolling
  • -t: Save files without backup
  • -v: View file (read-only)
  • -w: Disable line wrapping

Essential Keyboard Shortcuts

File Operations

  • Ctrl+O: Save file
  • Ctrl+X: Exit nano
  • Ctrl+R: Insert another file
  • Ctrl+G: Display help

Editing

  • Ctrl+K: Cut current line
  • Ctrl+U: Paste cut text
  • Ctrl+6: Set mark (for selection)
  • Alt+6: Copy marked text
  • Ctrl+A: Go to beginning of line
  • Ctrl+E: Go to end of line
  • Ctrl+W: Search for text
  • Ctrl+\: Search and replace

Navigation

  • Ctrl+V: Next page
  • Ctrl+Y: Previous page
  • Ctrl+P: Previous line
  • Ctrl+N: Next line
  • Ctrl+F: Forward one character
  • Ctrl+B: Backward one character

Practical Examples

Edit configuration file

nano /etc/nginx/nginx.conf

Create new file with line numbers

nano -l newfile.txt

Edit file with backup

nano -B important.conf

View file in read-only mode

nano -v logfile.log

Edit with auto-indent enabled

nano -i script.sh

Set line wrapping at column 80

nano -r 80 longfile.txt

Search and Replace

Search for text

Ctrl+W (then type search term)

Search and replace

Ctrl+\ (then type search term, press Enter, type replacement)

Find next occurrence

Alt+W

Best Practices

When to Use Nano

  • Quick text editing tasks
  • Configuration file editing
  • Simple script creation
  • Learning text editing in terminal
  • When you need a simple, non-intimidating editor

Important Notes

  • Always save before exiting (Ctrl+O, then Ctrl+X)
  • Use Ctrl+G for help when unsure about shortcuts
  • Backup important files before editing
  • Be careful when editing system configuration files
  • Use sudo when editing files that require root privileges

See Also

  • vi - Advanced text editor
  • vim - Enhanced vi editor
  • emacs - Extensible text editor
  • cat - Display file contents