|

Linux CLI 24 ๐Ÿง nano CLI editor

Nano is a popular command-line text editor on Unix-based systems. It’s open source, simple, and powerful โ€” a favorite for beginners and system administrators alike.


Introduction and Installation

Nano comes pre-installed on many Linux distributions. If not, install it with:

Debian / Ubuntu:

sudo apt-get install nano

RHEL / Fedora:

sudo yum install nano

Arch / Manjaro:

sudo pacman -S nano

openSUSE:

sudo zypper install nano

Opening Files with Nano

nano filename
nano aaa.txt
nano /etc/hosts
nano
CommandDescription
nano filenameOpen or create filename
nano /etc/hostsOpen a system file (may need sudo)
nanoStart empty โ€” specify name when saving

Examples:

# Create or open a file
$ nano notes.txt

# Open a system file with sudo
$ sudo nano /etc/hosts

# Start empty โ€” save with name later
$ nano
# (type content, then Ctrl+O to specify filename)

Search Text and Navigation

Searching

Ctrl + W      โ†’  Enter search term, press Enter
Alt + W       โ†’  Continue searching for the same term
Ctrl + R      โ†’  Find and replace (after Ctrl+W)
ShortcutAction
Ctrl + WSearch forward
Alt + WFind next occurrence
Ctrl + RReplace (search + replace)

Search example:

# In nano:
# 1. Press Ctrl+W
# 2. Type "error"
# 3. Press Enter
# โ†’ Cursor jumps to first "error"
# 4. Press Alt+W repeatedly to find next

Find and replace:

# 1. Press Ctrl+W โ†’ search for "old"
# 2. Press Enter โ†’ found
# 3. Press Ctrl+R โ†’ replace mode
# 4. Type "new"
# 5. Press Enter
# 6. Press Y to replace one, or A to replace all

Navigation

Use arrow keys or these shortcuts:

ShortcutAction
โ†‘ โ†“ โ† โ†’Move cursor
Ctrl + PMove up
Ctrl + NMove down
Ctrl + FMove forward (right)
Ctrl + BMove backward (left)
Home / Ctrl + ABeginning of line
End / Ctrl + EEnd of line
PgUp / Ctrl + YPage up
PgDn / Ctrl + VPage down

Visual:

         Ctrl + P / โ†‘
              โ–ฒ
              โ”‚
Ctrl + B  โ—€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ–ถ  Ctrl + F
  / โ†         โ”‚         / โ†’
              โ–ผ
         Ctrl + N / โ†“

         Ctrl + A / Home โ”€โ”€โ†’ Beginning of line
         Ctrl + E / End  โ”€โ”€โ†’ End of line
         Ctrl + Y / PgUp โ”€โ”€โ†’ Page up
         Ctrl + V / PgDn โ”€โ”€โ†’ Page down

Edit, Save, and Exit

Selecting Text

ShortcutAction
Alt + AStart selection (mark)
Arrow keysExtend selection
Alt + AStop selection

Example:

# 1. Position cursor at start of text
# 2. Press Alt+A โ†’ "Mark Set" appears
# 3. Use arrows to select text
# 4. Press Alt+A again to cancel marking

Copy and Paste

ShortcutAction
Alt + 6Copy selection to clipboard
Ctrl + KCut selection or cut to end of line
Ctrl + UPaste or cut to start of line
Ctrl + YPaste the cut from Ctrl + U

Note: Ctrl + K and Ctrl + U have dual purposes:

  • With selection: Cut the selected text
  • Without selection: Cut to end/start of line

Examples:

# Copy and paste:
# 1. Select text with Alt+A + arrows
# 2. Alt+6 to copy
# 3. Move cursor to where you want to paste
# 4. Ctrl+U to paste

# Cut a line:
# 1. Cursor anywhere on line
# 2. Ctrl+K โ†’ cuts to end of line
# 3. Move to new position
# 4. Ctrl+U โ†’ pastes it

# Cut and paste multiple lines:
# 1. Press Ctrl+K repeatedly to cut lines
# 2. Move cursor
# 3. Ctrl+U to paste all at once

Saving and Exiting

ShortcutAction
Ctrl + OSave the file (write out)
Ctrl + XExit nano
Ctrl + GShow help menu

Saving a file:

# 1. Press Ctrl+O
# 2. Press Enter to confirm filename
#    (or type a new name to save as)
# โ†’ File saved

Exiting with unsaved changes:

# 1. Press Ctrl+X
# 2. Nano asks: "Save modified buffer?"
# 3. Press Y to save, N to discard, Ctrl+C to cancel

Complete Example Session

# ============================================
# PART 1: CREATE A NEW FILE
# ============================================

$ nano notes.txt
# Empty editor opens
# Type content:
# Hello, this is my first note.
# This is the second line.
# This is the third line.

# Save and exit:
# Ctrl+O โ†’ Enter โ†’ Ctrl+X

# ============================================
# PART 2: EDIT AN EXISTING FILE
# ============================================

$ nano notes.txt
# File opens with previous content

# Navigate to end of file:
# Ctrl+E (end of line)
# Ctrl+N (move down)

# Add new line:
# This is the fourth line.

# Save:
# Ctrl+O โ†’ Enter

# ============================================
# PART 3: SEARCH AND REPLACE
# ============================================

$ nano notes.txt

# Search for "second":
# 1. Ctrl+W
# 2. Type "second"
# 3. Enter
# โ†’ Cursor at "second"

# Find next:
# Alt+W (repeats search)

# Find and replace:
# 1. Ctrl+W โ†’ search "second"
# 2. Enter
# 3. Ctrl+R โ†’ replace
# 4. Type "2nd"
# 5. Enter
# 6. Press Y (replace this) or A (replace all)

# ============================================
# PART 4: SELECT, COPY, PASTE
# ============================================

$ nano notes.txt

# Select a block:
# 1. Move cursor to start
# 2. Alt+A (mark set)
# 3. Arrow keys to extend selection

# Copy:
# Alt+6

# Move cursor to end

# Paste:
# Ctrl+U

# ============================================
# PART 5: CUT AND PASTE LINES
# ============================================

$ nano notes.txt

# Cut current line to end:
# Ctrl+K

# Cut more lines:
# Ctrl+K (again)

# Move cursor to desired position

# Paste all cut lines:
# Ctrl+U

# ============================================
# PART 6: OPEN A SYSTEM FILE
# ============================================

$ sudo nano /etc/hosts
# Edit the file

# Add a line:
# 127.0.0.1    myapp.local

# Save and exit:
# Ctrl+O โ†’ Enter โ†’ Ctrl+X

# ============================================
# PART 7: HELP MENU
# ============================================

$ nano
# Ctrl+G โ†’ shows help menu with all shortcuts
# Ctrl+X โ†’ exit help

Complete Shortcut Reference

File Operations

ShortcutAction
Ctrl + OSave (Write Out)
Ctrl + XExit
Ctrl + RRead file into current
Ctrl + GHelp

Search

ShortcutAction
Ctrl + WSearch
Alt + WFind next
Ctrl + RReplace

Navigation

ShortcutAction
โ†‘ โ†“ โ† โ†’Move cursor
Ctrl + PUp
Ctrl + NDown
Ctrl + FForward
Ctrl + BBackward
Ctrl + A / HomeStart of line
Ctrl + E / EndEnd of line
Ctrl + Y / PgUpPage up
Ctrl + V / PgDnPage down

Editing

ShortcutAction
Alt + AStart/stop selection
Alt + 6Copy selection
Ctrl + KCut selection/line-end
Ctrl + UPaste/cut line-start
Ctrl + YPaste the Ctrl+U cut
Ctrl + DDelete character under cursor
BackspaceDelete character before cursor
Ctrl + HDelete character before cursor
Alt + DDelete word forward
Alt + BackspaceDelete word backward

Screen

ShortcutAction
Ctrl + LRedraw screen
Ctrl + _Go to line number

Misc

ShortcutAction
Ctrl + CShow cursor position
Ctrl + JJustify paragraph
Ctrl + TSpell check (if available)

Nano vs Vim vs Emacs

AspectNanoVimEmacs
Learning curveโœ… EasyโŒ Steepโš ๏ธ Moderate
Modesโœ… NoneโŒ MultipleโŒ Multiple
Shortcut styleCtrl+keySingle keysCtrl+/Alt+
Powerโœ… Goodโœ…โœ… Excellentโœ…โœ… Excellent
Best forBeginnersPower usersProgrammers
Availabilityโœ… Universalโœ… Universalโš ๏ธ Less common

Best Practices

โœ… Do This:

# Use nano for quick edits
sudo nano /etc/hosts

# Use Ctrl+O to save often
# (avoid losing work)

# Use Ctrl+G when unsure
# (help is always available)

# Use Alt+A + arrows for selections
# (then Alt+6 to copy, Ctrl+U to paste)

# Use Ctrl+W for searching
# (Alt+W to find next)

# Use sudo for system files
sudo nano /etc/ssh/sshd_config

โŒ Don’t Do This:

# Don't forget to save before exit
# Ctrl+X without Ctrl+O โ†’ may lose changes

# Don't use sudo on your own files
sudo nano ~/notes.txt   # โš ๏ธ Creates root-owned file!
nano ~/notes.txt        # โœ…

# Don't panic if you press wrong key
# Ctrl+C cancels most operations

# Don't forget: Ctrl+K cuts to end of line
# (not just the whole line)

# Don't confuse Ctrl+U and Ctrl+Y
# Ctrl+U: paste OR cut to start
# Ctrl+Y: paste the cut from Ctrl+U

Common Pitfalls

PitfallProblemSolution
Forgot to saveLost changesAlways Ctrl+O before exit
Confused Ctrl+KCuts line to endCursor position matters
Ctrl+U didn’t pasteDepending on contextCtrl+Y for the pasted buffer
Can’t exit nanoStuck in editorCtrl+X, then Y or N
Wrong file permissionsCan’t saveUse sudo nano for system files
Accidentally deletedNo undo for multi-lineCtrl+U re-pastes the cut

Real-World Use Cases

1. Edit System Configuration

$ sudo nano /etc/ssh/sshd_config
# Edit config
# Ctrl+O โ†’ Enter โ†’ Ctrl+X
$ sudo systemctl restart sshd

2. Add a Host Entry

$ sudo nano /etc/hosts

# Add at end:
127.0.0.1    myapp.local

# Save and exit
$ ping myapp.local

3. Edit Crontab

$ crontab -e
# Opens in nano (if EDITOR=nano)
# Add cron jobs
# Save and exit

4. Write a Shell Script

$ nano backup.sh

#!/bin/bash
echo "Backup starting..."
tar -czf backup.tar.gz /home/kronos
echo "Backup complete!"

# Save, exit
$ chmod +x backup.sh
$ ./backup.sh

5. Fix a Broken Config

$ sudo nano /etc/nginx/nginx.conf
# Fix the problem
# Ctrl+O โ†’ Enter โ†’ Ctrl+X
$ sudo nginx -t               # Test config
$ sudo systemctl reload nginx

6. Write Documentation

$ nano README.md
# Type Markdown content
# Ctrl+O โ†’ Enter โ†’ Ctrl+X

7. Search and Replace in Bulk

$ nano config.txt
# Ctrl+W โ†’ "localhost" โ†’ Enter
# Ctrl+R โ†’ "127.0.0.1"
# Press A โ†’ replace all
# Ctrl+O โ†’ Enter โ†’ Ctrl+X

Visual: Nano Screen Layout

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  GNU nano 5.1  File: notes.txt               โ”‚  โ† Title bar
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚  Hello, this is my first note.               โ”‚
โ”‚  This is the second line.                    โ”‚
โ”‚  This is the third line.                     โ”‚
โ”‚  โ–Œ                                           โ”‚  โ† Cursor
โ”‚                                              โ”‚
โ”‚                                              โ”‚
โ”‚                                              โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ ^G Help    ^O Write Out  ^W Where Is         โ”‚  โ† Shortcut bar
โ”‚ ^K Cut     ^T Execute    ^C Location         โ”‚
โ”‚ ^X Exit    ^R Read File  ^\ Replace          โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Summary

FeatureShortcut
Open filenano file.txt
SaveCtrl + O
ExitCtrl + X
SearchCtrl + W
Find nextAlt + W
ReplaceCtrl + R
SelectAlt + A
CopyAlt + 6
CutCtrl + K
PasteCtrl + U
HelpCtrl + G

Key takeaways:

  • Nano is a simple, beginner-friendly editor โ€” no modes to learn
  • Install with sudo apt install nano (Debian) or sudo yum install nano (RHEL)
  • Open files with nano filename
  • Ctrl + O saves โ€” Ctrl + X exits
  • Ctrl + W searches โ€” Alt + W finds next โ€” Ctrl + R replaces
  • Alt + A starts selection, Alt + 6 copies, Ctrl + U pastes
  • Ctrl + K cuts to end of line โ€” Ctrl + U pastes it
  • Ctrl + G shows help โ€” always available if you forget a shortcut
  • Use sudo nano for system files โ€” but never on your own files
  • Save often with Ctrl+O โ€” no autosave!

Remember: Nano is your friendly command-line editor. Its shortcut bar at the bottom always shows the most common keys, and Ctrl+G brings up the complete help menu. The most important shortcuts are Ctrl+O (save), Ctrl+X (exit), and Ctrl+W (search). Once you know those three, you can handle almost any file. Master Ctrl+K for cutting lines and Ctrl+U for pasting โ€” these are how you move text around in nano!


Stop using slow, ad-bloated tool sites! ๐Ÿคฎ

๐Ÿ”Ž Search “KandZ Tools” on Google to use many professional utilities for free.

KandZ.me is the ultimate minimalist hub for:
โœ… Finance (Mortgage, Interest, Inflation)
โœ… Tech (Base64, JSON, Dev Suite, IP)
โœ… Health (BMI, BMR, TDEE)
โœ… Productivity (Timer, Workspace, QR)

โšก๏ธ Fast & Private
๐Ÿ”’ No data leaves your device
๐Ÿ’Ž 100% Free

๐Ÿ”— Use it now: https://tools.kandz.me
๐Ÿ”– Bookmark itโ€”youโ€™ll need it later!