Skip to main content

nano — Friendly Terminal Text Editing

Learning Focus

By the end of this lesson, you will be able to use nano to edit critical VPS files safely, jump directly to problem lines in WordPress and Nginx configs, and recover confidently with backups and read-only workflows.

Overview

nano is a lightweight terminal text editor focused on clarity and speed. It opens fast over SSH, shows key shortcuts directly in the interface, and is ideal when you need to patch configuration files without the learning curve of modal editors.

For WordPress VPS operations, nano is especially useful for targeted edits in wp-config.php, Nginx virtual host files, PHP-FPM settings, and cron-related scripts. You can open files at exact line numbers, run in read-only mode for safe reviews, and create automatic backups before saving.

Tool Snapshot
  • Core Function: Interactive terminal editor for quick, direct file modifications.
  • Primary Benefit: Simple key-driven workflow with low cognitive load during production maintenance.
  • Where to Use: WordPress configuration edits, Nginx/PHP troubleshooting, and incident-time hotfixes.
  • Workflow: nano [OPTIONS] [[+LINE[,COLUMN]] FILE]....

nano is part of the GNU nano package and is commonly available by default on Debian/Ubuntu-based VPS systems.

Installation (If Missing)

Install nano if it is not already present:

sudo apt update
sudo apt install -y nano

System Check

Ensure nano is available and check your version:

which nano # Expected: /usr/bin/nano
nano --version # Recommended: 6.0+

Syntax & Expression Rules

The command follows a logical structure that reads almost like a sentence:

nano [OPTIONS] [[+LINE[,COLUMN]] FILE]...
  • [OPTIONS]: Startup controls like -v (view mode), -l (line numbers), -B (backup), and -Y (syntax).
  • [+LINE[,COLUMN]]: Optional cursor placement before opening a file, such as +80 or +80,12.
  • [FILE]: One or more files to edit (for example /var/www/html/wp-config.php, /etc/nginx/nginx.conf).

If you need to open at the first match of a string, use +/STRING before the filename:

nano +/DB_HOST /var/www/html/wp-config.php

Reference Tables

Startup and Safety Controls

ExpressionDescriptionExample Syntax⭐ Rating
:--:--:--:--
-v, --viewOpen in read-only mode to prevent accidental writes.nano -v /etc/nginx/nginx.conf⭐⭐⭐⭐⭐
-B, --backupCreate a backup (~ suffix) when saving.nano -B /var/www/html/wp-config.php⭐⭐⭐⭐⭐
-C, --backupdir=<dir>Store uniquely numbered backups in a specific directory.nano -B -C /home/backups/nano /etc/nginx/nginx.conf⭐⭐⭐⭐
-l, --linenumbersShow line numbers in the editing pane.nano -l /var/log/nginx/error.log⭐⭐⭐⭐⭐
-c, --constantshowContinuously display cursor line/column position.nano -c /var/www/html/wp-config.php⭐⭐⭐⭐
-S, --softwrapSoft-wrap long lines across screen rows.nano -S /var/www/html/wp-content/debug.log⭐⭐⭐
-Y, --syntax=<name>Force a syntax highlighter by name.nano -Y php /var/www/html/wp-config.php⭐⭐⭐⭐
+LINE[,COLUMN]Start editing at a specific location.nano +120,1 /etc/nginx/nginx.conf⭐⭐⭐⭐⭐
+/STRINGJump to first occurrence of a string on open.nano +/server_name /etc/nginx/sites-available/example.com.conf⭐⭐⭐⭐
-R, --restrictedRestrict filesystem access for safer delegated editing.nano -R /var/www/html/wp-config.php⭐⭐⭐
-I, --ignorercfilesIgnore system/user nanorc files for predictable behavior.nano -I /var/www/html/wp-config.php⭐⭐⭐
-G, --lockingUse lock files to reduce concurrent edit conflicts.nano -G /etc/php/8.2/fpm/php.ini⭐⭐⭐⭐

Common In-Editor Actions

ActionDescriptionWordPress/VPS Use CaseExample Syntax
:--:--:--:--
Ctrl+OWrite current buffer to disk.Save wp-config.php after updating DB credentials.Press Ctrl+O, confirm filename, press Enter
Ctrl+XExit editor (prompts to save if modified).Leave safely after a quick production edit.Press Ctrl+X
Ctrl+WSearch forward for text.Find server_name or DB_PASSWORD quickly.Press Ctrl+W, type pattern, press Enter
Alt+WRepeat last search forward.Step through repeated error strings in a log.Press Alt+W repeatedly
Ctrl+\Search and replace text.Replace old domain references during migration.Press Ctrl+\, enter find/replace strings
Ctrl+KCut current line (or selected region).Remove obsolete directives cleanly.Place cursor, press Ctrl+K
Ctrl+UPaste last cut text.Reinsert moved Nginx or PHP directives.Press Ctrl+U
Ctrl+_Jump to a specific line and column.Navigate directly to lint or parser error lines.Press Ctrl+_, enter 87,1
Alt+ASet mark (start selection).Select a block before moving or deleting.Press Alt+A, move cursor, then Ctrl+K
Ctrl+GOpen built-in help.Confirm shortcut behavior mid-incident.Press Ctrl+G

Practical Use Cases

1. Verify nano version before maintenance

nano --version

Expected output:

GNU nano, version 7.2

Explanation: Prints the installed nano version and build details. Use case: Confirm feature availability before documenting or automating editor usage on multiple servers.

2. Open WordPress configuration for direct edit

nano /var/www/html/wp-config.php

Expected output:

[ Opened /var/www/html/wp-config.php in nano ]

Explanation: Opens the main WordPress config file in an interactive buffer. Use case: Update database settings, debug constants, or cache flags during troubleshooting.

3. Start at a specific line from an error report

nano +86 /var/www/html/wp-config.php

Expected output:

[ Cursor starts at line 86 ]

Explanation: Positions the cursor on line 86 immediately at open. Use case: Jump directly to the failing line shown in a PHP fatal error.

4. Start at an exact line and column

nano +42,9 /etc/nginx/nginx.conf

Expected output:

[ Cursor starts at line 42, column 9 ]

Explanation: Places the cursor with column precision. Use case: Quickly patch malformed directives flagged by nginx -t.

5. Open and jump to DB_HOST automatically

nano +/DB_HOST /var/www/html/wp-config.php

Expected output:

[ "DB_HOST" found ]

Explanation: Performs an initial search at startup. Use case: Move instantly to database host settings during migration checks.

6. Review Nginx config in read-only mode

nano -v /etc/nginx/nginx.conf

Expected output:

[ View mode: read-only ]

Explanation: Opens the file without allowing edits. Use case: Safe walkthroughs during production incident calls.

7. Enable line numbers while inspecting logs

nano -l /var/log/nginx/error.log

Expected output:

1 2026/02/23 10:14:20 [error] 3021#3021: *55 upstream timed out ...
2 2026/02/23 10:14:22 [error] 3021#3021: *57 connect() failed ...

Explanation: Adds a line-number gutter for easier reference. Use case: Share exact log lines in tickets or handoffs.

8. Keep cursor position visible at all times

nano -c /var/www/html/wp-config.php

Expected output:

line 35/210 (16%), col 12/44 (27%), char 928/6234 (14%)

Explanation: Displays a live position readout in the status area. Use case: Coordinate edits accurately with other administrators.

9. Soft-wrap long debug lines for readability

nano -S /var/www/html/wp-content/debug.log

Expected output:

[ Long lines are wrapped across screen rows ]

Explanation: Wraps display-only lines without changing file content. Use case: Read oversized stack traces over SSH without horizontal scrolling.

10. Force PHP syntax highlighting

nano -Y php /var/www/html/wp-config.php

Expected output:

[ Syntax highlighting: php ]

Explanation: Applies PHP syntax rules explicitly. Use case: Spot missing semicolons or malformed constants faster.

11. Edit virtual host file with sudo permissions

sudo nano /etc/nginx/sites-available/example.com.conf

Expected output:

[ Opened /etc/nginx/sites-available/example.com.conf ]

Explanation: Opens root-owned service config with write access. Use case: Apply domain routing or TLS fixes and save directly.

12. Save with automatic single backup

nano -B /var/www/html/wp-config.php

Expected output:

[ Wrote 210 lines ]
[ Backup created: /var/www/html/wp-config.php~ ]

Explanation: Creates a rollback copy when writing changes. Use case: Protect critical WordPress settings before risky edits.

13. Keep numbered backups in a dedicated folder

sudo nano -B -C /home/backups/nano /etc/nginx/nginx.conf

Expected output:

[ Wrote 122 lines ]
[ Backup created: /home/backups/nano/nginx.conf.1 ]

Explanation: Stores unique backup versions outside the source directory. Use case: Maintain an auditable history of production config changes.

14. Open multiple files as separate buffers

nano -F /var/www/html/wp-config.php /etc/nginx/nginx.conf

Expected output:

[ Opened 2 buffers ]

Explanation: Starts each file in a separate buffer for quick switching. Use case: Compare app and web-server config while debugging upstream issues.

15. Restrict filesystem actions during delegated support

nano -R /var/www/html/wp-config.php

Expected output:

[ Restricted mode enabled ]

Explanation: Limits operations like writing arbitrary paths. Use case: Safer access model for junior operators or temporary sessions.

16. Ignore nanorc files for deterministic behavior

nano -I /var/www/html/wp-config.php

Expected output:

[ Using built-in defaults (nanorc ignored) ]

Explanation: Bypasses system and user customizations. Use case: Reproduce editing behavior consistently across hosts.

17. Launch with a custom nanorc profile

nano -f /home/backups/nano/profiles/audit.nanorc /var/log/nginx/error.log

Expected output:

[ Loaded rcfile: /home/backups/nano/profiles/audit.nanorc ]

Explanation: Uses one explicit config file for options and syntax rules. Use case: Standardize incident-response viewing settings for the team.

18. Use lock files to reduce edit collisions

sudo nano -G /etc/php/8.2/fpm/php.ini

Expected output:

[ Lock file created for /etc/php/8.2/fpm/php.ini ]

Explanation: Enables vim-style lock-file behavior. Use case: Warn other admins that a sensitive config is actively being edited.

19. Load content from stdin for quick one-off edits

printf 'server_tokens off;\n' | nano -

Expected output:

[ Reading from standard input ]

Explanation: Opens piped content in an editable temporary buffer. Use case: Review generated snippets before pasting into production configs.

20. Recover from an emergency .save file

nano /var/www/html/wp-config.php.save

Expected output:

[ Opened recovery file: /var/www/html/wp-config.php.save ]

Explanation: Opens crash-recovery output created by nano. Use case: Restore unsaved work after SSH disconnects or terminal crashes.

Common Mistakes & Troubleshooting

ProblemCauseFix
:--:--:--
nano: command not foundNano package is missing on the host image.Install it: sudo apt update && sudo apt install -y nano.
Error writing ... Permission deniedYou opened a root-owned file without elevation.Reopen with permissions: sudo nano /etc/nginx/nginx.conf.
File changed unexpectedly during reviewFile was opened in writable mode instead of read-only.Use view mode for audits: nano -v /var/www/html/wp-config.php.
Line numbers are not visible-l flag (or equivalent config) is not enabled.Start with line numbers: nano -l /var/log/nginx/error.log.
No backup file exists after saveBackup mode was not enabled.Use backup flags: nano -B -C /home/backups/nano /etc/nginx/nginx.conf.
Search starts from top every sessionCursor positions are not being logged/restored.Enable position logging: nano -P /var/www/html/wp-config.php.

Best Practices

  • Use Read-Only First: Start with -v when inspecting production files, then reopen writable only when you are ready to change.
  • Always Keep Backups for Critical Files: Use -B and -C for wp-config.php, Nginx vhosts, and PHP-FPM configs.
  • Navigate by Error Line Numbers: Open directly with +LINE or Ctrl+_ to reduce manual scrolling and editing mistakes.
  • Standardize Team Behavior: Use -I or a shared -f /path/to/nanorc profile during incident response for predictable shortcuts and display.
  • Validate Immediately After Save: For service configs, run checks such as nginx -t right after edits to catch syntax issues before reload.

Hands-On Practice

Task: Safe Nginx Hotfix Workflow

  1. Open /etc/nginx/sites-available/example.com.conf in read-only mode and locate server_name.
  2. Reopen the same file with -B -C /home/backups/nano, apply the change, and save.
  3. Challenge: Open /var/log/nginx/error.log with line numbers, jump to an error line from nginx -t, and document the exact line/column location you fixed.

Connection to Other Concepts

  • micro: Use micro when you want a modern terminal editor with plugin support and richer defaults.
  • cat: Use cat for fast read-only output when you do not need interactive editing.
  • grep: Find exact strings first with grep, then jump to the file in nano for precise edits.
  • sed: Use sed for scripted, repeatable replacements across many files instead of manual per-file edits.

Visual Learning Diagram

What's Next: Proceed to Edit with micro to learn a modern terminal editor with plugin-driven workflows.