Editor nano is a console text editor. It is available in almost all Linux distributions, is available on macOS and can be run on Windows. nano is often used to edit configuration files when a GUI is not available.
Control in nano is carried out from the keyboard using hotkeys. At the bottom of the editor is a list of basic keyboard shortcuts. The ^ symbol represents the Ctrl key. For example, ^X means the keyboard shortcut Ctrl+X. Character case is not sensitive; Ctrl+X is equivalent to Ctrl+x .
Let's look at how to perform basic actions when working with nano.
Create a new file
To create a file, simply launch the editor without parameters. When you close the editor, you will need to enter a file name.
You can also immediately set the name of the new file:
After executing the command, the nano editor will launch and a new empty file will open for editing.
Open an existing file for editing
To edit an existing file, you need to launch the nano editor and specify the path to the file you want to open:
Saving changes
Save and continue working
The following message will appear in the status line: File Name to Write: file_name(if the file name is missing, then you need to enter the file name). To save changes, press Enter.
Save and exit
In this case, if you changed the file, the question will appear: " Save modified buffer (ANSWERING No Will DESTROY CHANGES)?". Press the y key. A question will appear asking you to enter a file name. Enter a new file name or just press Enter. The changes will be saved and the editor will close.
Exit without saving changes
To exit the editor and not save changes, use the keyboard shortcut:
Ctrl+X
There is a question" Save modified buffer ..?", press n.
Copy and paste
Copying and pasting rows
To cut entire line and place it in the buffer, move the cursor to the desired line and press:
Ctrl+K
To insert click the line from the buffer:
Ctrl+U
Copy and paste free text
To copy arbitrary text to the clipboard, you must first select it. To start selection Place the cursor at the beginning of the text you plan to copy and press:
Ctrl+6
Move the cursor, the text will be highlighted.
To copy selected text to the clipboard, press:
Alt+6
or, to cut selected text, click:
Ctrl+K
Move the cursor to the place where you want to paste the text from the buffer. To insert text from buffer click:
Ctrl+U
Search text
To search for text inside a file, use the keyboard shortcut:
Ctrl+W
You need to enter a search string and press Enter.
The cursor will be placed on the first occurrence of the searched text (relative to the cursor). To move to the next occurrence, click:
Alt+W
To stop searching, click:
Ctrl+C
Find and replace text
To find and replace text, use the keyboard shortcut:
Ctrl+\
You will be prompted to enter text to search. Enter a search string and press Enter.
You will then be asked to enter the text you want to replace with. Type a string and press Enter.
Next, a request will be issued to replace the found occurrence of the required string. You can press the A key to replace all occurrences in the file at once, or use the Y or N keys to replace or not replace found occurrences of the search string.
Hotkeys
To display information on all hotkeys, use the combination Ctrl+G.
The most commonly used nano hotkeys are:
Hotkeys | Description |
---|---|
Ctrl+A | Move the cursor to the beginning of the line. |
Ctrl+E | Move the cursor to the end of the line. |
Ctrl+Y | Move the cursor 1 page up (analogous to PageUp) |
Ctrl+V | Move the cursor 1 page down (analogous to PageDown) |
Ctrl+_ | Go to a specific line (you will need to enter a line number). |
Ctrl+C | Show what line and position the cursor is on. |
Ctrl+W | Search for text in a file. You must enter a search string. |
Ctrl+\ | Find and replace text in a file. First enter the search string, then the replacement string. |
Ctrl+D | Delete the character under the cursor. |
Ctrl+K | Delete the current line. |
Ctrl+O | Save changes without closing the editor. |
Ctrl+X | Exit the editor. If the file has been modified, you will be prompted to save your changes. |
Something else
A couple more interesting tricks when working with nano, which not everyone knows about.
Ctrl = Esc Esc
Instead of the Ctrl key, you can use double-clicking the Esc key. For example,
Esc+Esc+X
This is equivalent to Ctrl+X.
Only for reading
To open a file read-only, use the -v switch:
File backup
You can make sure that when a file is changed, a backup copy is created. To do this, use the -B switch:
If you change a file and save the changes, a backup copy of the file will be created, with the contents of the file as it was before the change. The backup name is the same as the original file name with a tilde ~ at the end.
The nano editor may well play the role of a kind of shock absorber for a novice user. Yes, this is not emacs, or even joe. But it copes with the configuration task successfully. And in mastering and handling it is as simple as a rake. It is no coincidence that many Linux distributions offer it as a system-wide option. In Gentoo Linux, where during installation the need to manually edit configuration files arises quite often - this is simply the only editor available at the system installation stage. In CRUX and Archlinux, however, during installation it is adjacent to vi - which imitates the original one, and therefore may also be preferable.
The nano editor is launched in the command line with the following syntax nano /file_path/file. rice. 1
If you specified a non-existent file, it will be created.
After running the above command, you will see something similar to Fig. 2.
I think there is no point in explaining that moving the cursor, as well as deleting text, is done using the corresponding keyboard keys, as in other editors. The remaining functions of nano are controlled using control sequences, the list of which was taken from http://posix.ru/apps/nano_editor/ and is given below.
In nano there are two types of control sequences - actual control sequences, Control+letter, and meta-sequences, Meta+litera. The former are used for text editing and file operations. Control sequences are partially duplicated by function keys F1-F16(call F13-F16- through combination Shift+F1-F4). Meta sequences are intended to change editor settings (the same result is achieved with command line options).
Let me remind you that on a PC keyboard the role of the Meta key is usually performed by pressing the key Alt(in some layouts - specifically Alt"a right, or, conversely, left), or pressing and releasing a key Escape.
All basic Control sequences are listed at the bottom of the terminal window.
Control sequences are as follows (in parentheses are duplicate function keys and, sometimes, Meta sequences):
- Control+G (F1) - call the full help menu;
- Control+X (F2) - exit the program;
- Control+O (F3) - record the current file;
- Control+R (F5) - insert a file into the current one;
- Control+W (F6) - search for text in the current file;
- Control+\ (F14 or Meta+R) - replacing text in the current file; First, the replacement text is entered, then, after clicking Enter- replaceable;
- Control+Y (F7 or PgUp) - move to the previous screen;
- Control+V (F8 or PgDwn) - move to the next screen;
- Control+K (F9) = deleting (Cut, cut) a line at the cursor position and storing it in a buffer (cutbuffer);
- Control+U - (F10) - inserts the contents of the cutbuffer into a line at the cursor position; if the latter has not changed, it performs the role of Undo (cancellation), which is not normally provided; can also be used for unlimited cloning of lines in an arbitrary part of the text - after deleting, it is enough to move the cursor to the desired place;
- Control+C (F11) - display information about the position of the cursor in the form of VR
- Control+T (F12) - spell checking (via an external spelling program, if it is installed and the corresponding option is enabled in the config, see below);
- Control+P- move the cursor one line up;
- Control+N- move the cursor one line down;
- Control+F- move the cursor one character forward;
- Control+B- move the cursor one character back;
- Control+A- moving the cursor to the beginning of the current line;
- Control+E- moving the cursor to the end of the current line;
- Control+L- redrawing the current screen;
- Control+^ (Meta+A) - selecting (and placing in the buffer) text, starting from the current cursor position;
- Control+D- deleting a character at the cursor position;
- Control+H- deleting a character to the left of the cursor;
- Control+I- insert a tab character;
- Control+J (F4) autocomplete the current paragraph;
- Control+M inserting a newline character (CR) at the cursor position;
- Control+_ (F13 or Meta+G) - jump to the specified line number.
Meta sequences usually work like switches. With their help, the following actions are performed:
- Meta+C- enable/disable permanent cursor position;
- Meta+I- enable/disable auto-indents;
- Meta+Z- enable/disable suspension;
- Meta+X- turn on/off the display of the hint zone;
- Meta+P- enable/disable pico editor emulation mode;
- Meta+W- enable/disable word wrap mode;
- Meta+M- enable/disable mouse support (only when building with gpm support;
- Meta+K- allow/prohibit cutting to the end;
- Meta+E- enable/disable the use of regular expressions (regexp).
And distributed under the GNU GPL license. Currently included in Ubuntu distributions by default and does not require installation.
To run nano, open a terminal and run:
Usage options
Using a standard command that allows you to get help on using the program, where you can view possible options for opening files and other information, you should run:
nano --helpWe get the “exhaust” given below. To be repeated, the command
Program_name --help
Standard for all console programs.
Usage: nano [OPTIONS] [[+ROW,COLUMN] FILE]... Option Long form Meaning -h, -? --help Show this message +ROW,COLUMN Start at the specified row and row -A --smarthome Enable smart home button -B --backup Keep backups of existing files -C<дир>--backupdir=<дир>Directory to store unique backups -D --boldtext Use bold font instead of normal -E --tabstospaces Convert tabs to spaces -F --multibuffer Allow multiple file buffers -H --historylog Store and read search/replace line history -I - -ignorercfiles Do not use on nanorc files -K --rebindkeypad Fix small keyboard problem -L --nonewlines Do not add empty lines at the end of the file -N --noconvert Do not convert from DOS/Mac format -O --morespace Use an extra line for editing -Q<стр>--quotestr=<стр>Quote line -R --restricted Restricted mode -S --smooth Line-by-line scrolling instead of half-screen -T<#чис>--tabsize=<#чис>Set tab width to #number of columns -U --quickblank Use quick clear status bar -V --version Show version and exit -W --wordbounds Use more precise word boundary detection -Y<стр>--syntax=<стр>Use syntax description for highlighting -c --const Always show cursor position -d --rebinddelete Fix Backspace/Delete problem -i --autoindent Automatically indent new lines -k --cut Cut from cursor to end of line -l --nofollow Don't follow symbolic links, override -m --mouse Allow mouse use -o<дир>--operatingdir=<дир>Set working directory -p --preserve Reserve XON (^Q) and XOFF (^S) buttons -q --quiet Silently ignore startup errors, such as rc file -r<#столбцы>--fill=<#столбцы>Set line break point to #columns -s<программа>--speller=<программа>Use an alternative spell checker -t --tempfile Auto-record on exit, no questions asked -u --undo Allow undo function [EXPERIMENTAL] -v --view View mode (read-only) -w --nowrap Don't wrap long lines - x --nohelp Don't show the two help lines at the bottom -z --suspend Allow suspending -$ --softwrap Enable soft line wraps -a, -b, -e, -f, -g, -j (ignored, for Pico compatibility )
nano help text
nano editor designed to emulate the functionality and ease of use of the original editor UW Pico. The editor is divided into 4 main parts: the top line contains the version of the program, the current name of the file that is being edited, and whether changes have been made to the current file. The second part is the main editing window, which displays the file being edited. The status bar - line 3 from the bottom - shows various important messages. The two lines below show the most commonly used key combinations.
The notation system for key combinations is as follows: Combinations with Control are indicated by the symbol (^) and are entered by pressing the Ctrl button or pressing Escape Esc twice; combinations with Esc are indicated by the Meta m symbol and can be entered using the Esc, Alt or Meta buttons, depending on the keyboard used. Also, pressing Esc twice and then entering a three-digit number from 000 to 255 will enter the corresponding character.
The following combinations are available in the main editing window. Alternative combinations are shown in brackets:
Ctrl + G or F1 - Show this help
Ctrl + X or F2 - Close current buffer / Exit nano
Ctrl + O or F3 - Write current file to disk
Ctrl + J or F4 - Align current paragraph
Ctrl + R or F5 - Paste another file into the current one
Ctrl + W or F6 - Search text or regular expression
Ctrl + Y or F7 - Go to previous screen
Ctrl + V or F8 - Go to next screen
Ctrl + K or F9 - Cut the current line and save it to the clipboard
Ctrl + U or F10 - Paste the contents of the clipboard into the current line
Ctrl + C or F11 - Show cursor position
Ctrl + T or F12 - Check spelling if available
m + \ or m + | - To the first line of the file
m + / or m + ? - To the last line of the file
Ctrl + _ or m + G - Go to the specified line number and row
Ctrl + \ or m + R - Replace text or regular expression
Ctrl + ^ or m + Alt - Mark text at the current cursor position
m + W - Repeat last search
m + ^ or m + 6 - Copy the current line and save it to the clipboard
m + ) - Increase line indent
m + ( - Decrease line indent
Ctrl + F - Forward one character
Ctrl + B - Back one character
Ctrl + Space - Forward one word
m + Space - Go back one word
Ctrl + P - Go to previous line
Ctrl + N - Go to next line
Ctrl + Alt - Go to the beginning of the current line
Ctrl + E - To the end of the current line
m + (or m + 9 - To the beginning of the current paragraph; then to the next paragraph
m +) or m + 0 - To the end of the current paragraph; then the next paragraph
m + ] - To the corresponding bracket
m + − or m + _ - Scroll up one line without moving the cursor
m + + or m + = - Scroll down one line without moving the cursor
m+< или m + , - Переключить на предыдущий буфер
m + > or m + . - Switch to next buffer
m + V - Paste the following key combination as is
Ctrl + I - Insert tab at cursor position
Ctrl + M - Insert line at cursor position
Ctrl + D - Delete the character under the cursor
Ctrl + H - Delete character to the left of the cursor
m + T - Cut from current position to end of file
m + J - Align entire file
m + D - Count the number of words, lines and characters
Ctrl + L - Refresh current screen
Ctrl + Z - Pause editor (if enabled)
m + X - Help mode enable/disable
m + C - Constant display of enable/disable position
m + O - Use an additional line to edit enable/disable
m + Shift - Smooth scrolling enable/disable
m + P - Display spaces enable/disable
m + Y - Syntax highlighting enable/disable
m + H - Smart home button enable/disable
m + I - Allow/disable auto-indents
m + K - Cut to the end enable/disable
m + L - Automatic line breaking enable/disable
m + Q - Convert tabs to spaces input enable/disable
m + B - Make backups allow/disable
m + F - Multiple file buffers enable/disable
m+M - Mouse support enable/disable
m + N - Without conversion from DOS/Mac format, enable/disable
m + Z - Suspend enable/disable
m + $ - Soft line breaks enable/disable
Syntax highlighting
On remote servers, you can use nano to edit configs - a fast, understandable, simple text editor with syntax highlighting. Agree, it's very convenient
1. Let's find where the example .nanorc files are located in our system. On Ubuntu they are usually in the /usr/share/nano/ directory. Let's copy the configuration file to our directory:
$ cp / etc/ nanorc ~/ .nanorc2. Add lines to the file ~/.nanorc(on Ubuntu configuration examples are included) to highlight the files we need if they are not in the standard configuration file:
## TeX include "/usr/share/nano/patch.nanorc"## POV-Ray include "/usr/share/nano/pov.nanorc" ## Perl include "/usr/share/nano/perl.nanorc" ## Nanorc files include "/usr/share/nano/nanorc.nanorc"## Python include "/usr/share/nano/python.nanorc"## C/C++ include "/usr/share/nano/c.nanorc" ## Groff include "/usr/share/nano/groff.nanorc"## Assembler include "/usr/share/nano/asm.nanorc" ## Ruby include "/usr/share/nano/ruby.nanorc" ## Manpages include "/usr/share/nano/man.nanorc" ## HTML include "/usr/share/nano/html.nanorc" ## Bourne shell scripts include "/usr/share/nano/sh.nanorc" ## Sun Java include "/usr/share/nano/java.nanorc"3. If this is not enough, then take the Syntax Highlight Pack and adjust the highlighting when editing anything and everything.
Probably every one of those who have visited the Linux console has used the hero of today’s article at least once. It's hard to imagine any Linux distribution without it. It is mentioned in many articles on setting up any Linux software. Its simplicity allows beginners to quickly solve problems. The administration pros grin at the sight of him. Those who have become a little stronger in the field of administration consider its use bad manners and a sign of insufficient professionalism. But we know that they themselves use it when others do not see.
So, the hero of our review today is the GNU nano console text editor.
Of all the console text editors, nano is probably the most popular. After all, even users of vim, emacs and other powerful text processing tools still regularly turn to nano for help. There are, of course, individuals who boycott its use, but of all my friends, only one fundamentally refuses to enter the coveted four letters into the terminal.
It would seem, why talk about using such a simple product? The goal is the same - we all get used to standard scenarios of interaction with software products, as a result, some of the functionality slips away.
Let's get started. To install nano, if it suddenly doesn’t work, you need to run the command:
apt-get install nano
Launched by nano command
nano filename
or with additional options:
nano –Option1 Option2 … OptionN + line, column filename
Nano launch keys allow you to use useful features of the utility immediately after start.
Let's create a text file and play with it a little.
nano ~/test. htm |
Like other editors, nano will create a new file after attempting to save if it did not exist before.
We were presented with a minimalistic editor interface. We can write text and navigate through the file in standard ways by pressing arrows. This scenario is probably where 99% of the examples of use are exhausted. But I strongly recommend exploring all its functionality. Otherwise, most people think that nano is an analogue of Notepad in Windows.
All the editor’s capabilities are reflected in a table I specially prepared. Basic commands are executed using the Ctrl+key key combinations. Hotkeys with the Meta key, which is usually assigned to Alt or Win, are also actively used.
nano capabilities table:
Fn | Ctrl+ | Meta+ | Config. file | Start key | Description |
---|---|---|---|---|---|
F1 | Ctrl+G | Calling help | |||
F2 | Ctrl+X | Exit the program. If the file has been modified, the program will ask if the buffer should be saved. The answer will be the standard Y/N. If you confirm the save, the utility will ask for the file name and path. | |||
F3 | Ctrl+O | Write file to disk | |||
F4 | Ctrl+J | Align paragraph. Paragraphs are separated by blank lines. If alignment is not required, the cursor will move to the next one. It is important that the alignment will match the width of the current terminal | |||
F5 | Ctrl+R | Inserting another file into the current one. One of my favorite features. After clicking, you will be offered a choice. Either specify the path to the file (TAB works great), or use Ctrl+T to select a file, or paste the output of an external source (for example, nslookup site). Ctrl+C will stop the execution of looped commands, so you can safely try ping 8.8.8.8 | |||
F6 | Ctrl+W | Search text. You can use regular expressions | |||
F7 | Ctrl+Y | Page forward | |||
F8 | Ctrl+V | Page back | |||
F9 | Ctrl+K | Cut the current line and save it to the clipboard | |||
Meta+Crtl or Meta+6 | Copy the current line and save it to the clipboard | ||||
F10 | Ctrl+U | Insert Row | |||
F11 | Ctrl+C | Show current cursor position | |||
F12 | Ctrl+T | Check spelling. An external speller is required for operation. The speller is specified in the nano config in the set speller "Speller" parameter | |||
F13 | Crtl+_ | Meta+G | +row, column | Go by line and row number. In the menu that appears, you must specify the number, row, separated by commas. | |
F14 | Crtl+\ | Meta+R | Replace text or regular expression | ||
F15 | Crtl+Crtl | Meta+A | Mark text at current cursor position | ||
F16 | Meta+W | Repeat last search | |||
Meta+) | Increase line indent | ||||
Meta+( | Decrease line indent | ||||
Crtl+F | Forward one character | ||||
Crtl+B | Back one character | ||||
Crtl+Space | One word forward | ||||
Meta+Space | Back one word | ||||
Crtl+P | To previous line | ||||
Crtl+N | To next line | ||||
Crtl+A | To the beginning of the current line | ||||
Crtl+E | To the end of the current line | ||||
Meta+(or Meta+9 | To the beginning of the current paragraph, then the next paragraph | ||||
Meta+) or Meta+0 | At the end of the current paragraph, then the next paragraph | ||||
Meta+- or Meta+_ | Scroll up one line without moving the cursor | ||||
Meta++ or Meta+= | Scroll down one line without moving the cursor | ||||
Meta+ | Switch to previous buffer | ||||
Meta+> or Meta+. | Switch to next buffer | ||||
Meta+V | Paste the following key combination as is | ||||
Ctrl+I | Insert tab at cursor position | ||||
Ctrl+M | Insert line at cursor position | ||||
Ctrl+D | Delete the character under the cursor | ||||
Ctrl+H | Delete the character to the left of the cursor | ||||
Meta+T | Cut from current position to end of file | ||||
Meta+J | Align entire file | ||||
Meta+D | Count the number of words, lines and characters | ||||
Ctrl+L | Refresh current screen | ||||
Ctrl+Z | Pause editor | ||||
Meta+X | Help mode enable/disable | ||||
Meta+C | Permanent display of enable/disable position | ||||
Meta+O | Using an additional line to edit enable/disable | ||||
Meta+S | set smooth | -S --smooth | Smooth scrolling enable/disable | ||
Meta+P | Display spaces enable/disable | ||||
Meta+Y | Syntax highlighting enable/disable. The backlight types are configured in the config file. | ||||
Meta+H | set smarthome | Smart home button enable/disable | |||
Meta+I | set autoindent | -i --autoinden | Allow/disable auto-indents | ||
Meta+K | set cut | Cut to the end enable/disable | |||
Meta+L | -w --nowrap | Automatic line splitting allow/deny | |||
Meta+Q | set tabstospaces | Convert tabs to spaces input allow/disable | |||
Meta+B | Allow/deny make backups | ||||
Meta+F | set multibuffer | Multiple file buffers enable/disable | |||
Meta+M | set mouse | Mouse support enable/disable | |||
Meta+N | set noconvert | Without conversion from DOS/Mac format, allow/disable | |||
Meta+Z | Suspend allow/deny | ||||
Meta+$ | Soft line breaks enable/disable | ||||
set undo | -u --undo | Allow undo function | |||
Meta+U | Undo if allowed | ||||
Meta+E | Redo if allowed | ||||
set view | -v --view | View Mode | |||
-x --nohelp | Don't show two help lines at the bottom | ||||
set backup | -B --backup | Keep backup copies of existing files. For example, if you run the command nano –B file.txt at the time of saving, 2 files will be created: file.txt - the edited file and file.txt~ - will have the contents of file.txt before the last save. | |||
set historylog | Enable historylog |
Nano is a command line text editor that comes pre-installed on almost every Linux distribution. It is often preferred by new users due to its simplicity compared to other command line text editors such as vi/vim And emacs. It has many useful features such as syntax highlighting, line numbering, easy search and many more.
Installing Nano Editor on Linux
If for any reason nano is not already installed on your Linux distribution, you should be able to install it easily using the following commands:
# apt install nano [For Ubuntu/Debian] # yum install nano [For CentOS/Fedora]
Nano Hotkeys
Nano uses keyboard shortcuts for various functions such as searching for text in a file, aligning text, etc. These shortcuts are very easy to see while editing a file. They change automatically depending on what actions you take.
One thing you should know is that a keyboard shortcut with a ^ icon and a symbol (such as ^W) is a combination of the Ctrl key and that symbol (Ctrl + W in our example).
A combination shown to begin with M means it must be completed by pressing the Alt key and the next character.
Below are the options you will see when you first open nano :
- G Get help
- ^O Write down
- ^W Where
- ^K Cut text
- ^J Align
- ^C Current position
- M-U cancel (back)
- ^X Exit
- ^R Read file
- ^\ Replace
- ^U Split text
- ^T Check spelling
- ^_ Go to line
- M-E cancel (forward)
You don't need to remember every option since it's always in front of you. You can get a full list of keyboard shortcuts by pressing ^G (or pressing F1), which will open nano's help menu. You will notice that some shortcuts can be used with a single key.
For example, F1 for help or F2 to exit nano.
Nano Editor Keyboard Shortcuts
Creating a new file in Nano
Creating a new file is as easy as running nano:
This will open the editor and after saving the file, it will ask you to provide a name to save the new file with.
Create a new file in Nano
Open file in Nano
To open the file you can run:
$nano ~/my_text_file.txt
The above command will try to open the file "my_text_file.txt" from your home directory. If the file does not exist, nano will try to create it.
Sometimes you may need to open a file and go to an exact row or column. Nano allows you to do this with:
$ nano +line,columns file
For example:
$ nano +3.2 ~/.bashrc
Will open your .bashrc file and the cursor will be located on the third line, second column.
Opening a file in Nano
Editing Files in Nano
After opening or creating files, you can start editing/recording immediately. Unlike vim, V nano there is no need to switch to edit mode. To move the cursor around the file, you can use the arrow keys on your keyboard.
Editing a file in Nano
Searching for text in Nano
You can search for text inside a file using ^W , which represents the " Where" This will open a search box above the menu where you can enter the text you're looking for:
Searching for text in Nano
You'll also see the bottom menu change to show some additional options. They pretty much explain themselves, so we'll look at the more important ones.
- Search with regular expressions- Press M-R (Alt + R keys) and enter your query using the regular expressions you want to use.
- Go to line- press ^T (Ctrl + T) and then the line where you want to move the cursor.
- Replace text— press the ^R (Ctrl + T) button in search mode or ^\ in normal mode. You will be prompted to enter your original text, after pressing Enter you will be prompted to enter the text that will be used for the replacement. Finally, you will be asked whether you want to replace the matching instance of your search or all matches. If you select "No", the cursor will be moved to the next match.
- Go to first line— press ^Y (Ctrl + Y).
- Go to last line- press ^V (Ctrl + V).
Copy/Paste/Cut Text in Nano
Nano's interface is very similar to GUI text editors. If you want to copy or cut text in a graphics editor, you first need to select it. The same thing happens in nano. To mark up text, press Ctrl + ^, then move the cursors using the arrow keys.
- To copy selected text, press Alt + ^.
- To cut selected text, press ^K (Ctrl + K).
- To paste the selected text, move the cursor to the desired position and press ^U (Ctrl + U).
Copying and pasting text in Nano
Save file to Nano
If you want to save the current changes to the file, press the combination ^O (Ctrl + O). If you are editing a new file, you will be prompted to provide a name for the file. This will save your current changes and nano will remain open so you can continue making changes to the file.
Save file with backup
Sometimes when editing a file, you may need to keep temporary copies of the same file just in case. You can use the -B option in nano, which will create a backup copy of the file you are editing. You can use it in combination with the -C option to tell nano where to save these backups as shown in the example:
$ nano -BC ~/backups myfile.txt
The above steps will make backup copies of the file myfile.txt in folder " backups", located in the user's home directory. Note that the backup directory must exist, otherwise nano will tell you that the directory is invalid.
Exit Nano Editor
To exit nano, simply press ^X (Ctrl+X keys). If the file has not yet been saved, you will be prompted to save changes using yes/no or cancel exit.
Conclusion
Nano is an easy-to-use command line text editor that attracts users with its simplicity. Its interface is similar to that of graphical editors, making it ideal for Linux newbies.