Using Nano
Last updated
Last updated
Nano is a simple, user-friendly text editor included with most Linux distributions. It’s ideal for quick file and configuration edits directly from the terminal.
Open a File in Nano:
To open a file (or create one if it doesn’t exist), use:
Example:
This opens myfile.txt
for editing.
Open Nano Without a File:
If you want to open Nano without specifying a file, type:
This starts a blank session where you can start typing and later choose to save or discard the file.
Nano has a set of commands accessible via the keyboard. Here’s a rundown of the essentials:
Navigating in Nano:
Arrow Keys: Move up, down, left, or right within the file.
Page Up / Page Down: Quickly scroll up or down a page.
Ctrl + _ (underscore): Jump to a specific line and column by entering the line number.
Editing Text:
Insert Text: Type as you normally would.
Delete Text: Use the Backspace
or Delete
key to remove characters.
Cut, Copy, and Paste:
Cut Text: Use Ctrl + K
to cut the current line. Repeat to cut multiple lines.
Copy Text: Use Alt + 6
to copy the current line. (Hold Alt
and press 6
.)
Paste Text: Use Ctrl + U
to paste the text at the cursor’s location.
Search and Replace:
Search: Press Ctrl + W
, type the search term, and press Enter. Nano will jump to the first match.
Find Next: Press Ctrl + W
again and hit Enter without typing to jump to the next instance.
Replace: Use Ctrl + \
and follow the prompts to replace text.
Save Changes:
Press Ctrl + O
(letter O, for "output"), then hit Enter to confirm the filename.
Nano displays the filename at the bottom of the screen for verification.
Exit Nano:
Press Ctrl + X
. If there are unsaved changes, Nano will prompt you to save before exiting. Type Y
(Yes) or N
(No), and press Enter.
Show Help: Press Ctrl + G
to access the help menu, which lists all available commands.
Undo/Redo: Use Alt + U
to undo and Alt + E
to redo changes.
Show Line Numbers: Start Nano with the -l
option for line numbers:
Open a file for editing:
Edit the content by typing directly into the editor.
To save, press Ctrl + O
, confirm the filename with Enter.
To exit, press Ctrl + X
.
Arrow Keys Don’t Work: Ensure Num Lock is off or try using Ctrl
key combinations if you’re in a minimal terminal.
Permission Denied: If editing a file that requires root permissions, use sudo
before the command:
Nano is mainly used for quick edits, and it’s efficient and simple to learn. You'll find yourself making quick changes to the .sh files for the bot.