Linux nano
Commands
Overview
nano
is a simple and user-friendly text editor for the command line. It is often used for editing configuration files and scripting. This document provides a guide to common nano
commands and operations.
Basic Commands
Open a File
To open a file in nano
, simply specify the file name.
Example
Save Changes
To save changes while editing, press Ctrl + O
(Write Out), then press Enter
to confirm the file name.
Example
- Edit the file.
- Press
Ctrl + O
. - Press
Enter
.
Exit nano
To exit nano
, press Ctrl + X
. If you have unsaved changes, nano
will prompt you to save them.
Example
- Press
Ctrl + X
. - If prompted to save changes, press
Y
(Yes) orN
(No).
Cut Text
To cut text, use Ctrl + K
. This will cut the current line or selected text.
Example
- Place the cursor on the line you want to cut.
- Press
Ctrl + K
. - The line will be removed and stored in the clipboard.
Paste Text
To paste text that was cut or copied, use Ctrl + U
.
Example
- Move the cursor to the location where you want to paste.
- Press
Ctrl + U
.
Copy Text
To copy text, use Ctrl + ^
to set the mark, move the cursor to select the text, and then press Ctrl + K
to cut. Paste it using Ctrl + U
.
Example
- Press
Ctrl + ^
to set the mark. - Move the cursor to select the text.
- Press
Ctrl + K
to cut the selected text. - Move the cursor to the paste location.
- Press
Ctrl + U
to paste.
Search for Text
To search for text within the file, press Ctrl + W
(Where Is), then enter the search term and press Enter
.
Example
- Press
Ctrl + W
. - Enter the search term.
- Press
Enter
.
Replace Text
To replace text, press Ctrl + \
(Replace), then enter the search term, press Enter
, enter the replacement term, and press Enter
.
Example
- Press
Ctrl + \
. - Enter the search term.
- Press
Enter
. - Enter the replacement term.
- Press
Enter
.
Go to Line Number
To move the cursor to a specific line number, press Ctrl + _
(Underscore), enter the line number, and press Enter
.
Example
- Press
Ctrl + _
. - Enter the line number (e.g.,
10
). - Press
Enter
.
Show Line Numbers
To enable line numbers, press Ctrl + C
to view the current line number, or check the status bar for line numbers.
Example
- Press
Ctrl + C
to view the current line number. - Check the status bar at the bottom of the editor.
Summary
nano
is a powerful yet easy-to-use text editor that allows you to efficiently edit files from the command line. Understanding these basic commands will help you navigate and modify files effectively. For more detailed information, refer to the nano
man pages by running man nano
in the terminal.