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 fileCtrl+X: Exit nanoCtrl+R: Insert another fileCtrl+G: Display help
Editing
Ctrl+K: Cut current lineCtrl+U: Paste cut textCtrl+6: Set mark (for selection)Alt+6: Copy marked textCtrl+A: Go to beginning of lineCtrl+E: Go to end of lineCtrl+W: Search for textCtrl+\: Search and replace
Navigation
Ctrl+V: Next pageCtrl+Y: Previous pageCtrl+P: Previous lineCtrl+N: Next lineCtrl+F: Forward one characterCtrl+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