The nano team editor. How do I use Nano on Linux? (nano text editor)

And Unix-like operating systems.

GNU nano is a clone of the well-known Pico editor. It was developed in 1991 and was originally named TIP. However, in 2000 it was renamed. Official resource -nano-editor.org.

The new editor is based on the curses library and is released under the GNU GPL license. Currently included in Ubuntu distributions by default and does not need to be installed.

How to get started? To start the console editor, you need to open a terminal (you need to find it in the Applications-Standard menu) and run the command:nano ... To create and open a file, the command -# nano filename .

To work with it you only need a keyboard. Move the mouse away.

At its core, Nano is designed to emulate the functionality and usability of the original UW Pico. The editor is divided into 4 parts. The first one displays the version of the program, the name of the file and the current changes in it. The second is the file that is currently being edited. The third bottom section shows important messages. The fourth shows the combinations that are most commonly used.

The editor is controlled by a keyboard shortcut. Let's look at some examples: save the current documentctrl + o , access to the search menuctrl + w to get the available keyboard shortcutsctrl + g ... Also used shortcuts with Meta keys, for example,meta + s - enable or disable smooth scrolling.

The easy-to-learn Nano is suitable for newbie users, but it also handles configuration tasks flawlessly.An improved version of nano 2.0 distinguished itself by its current capabilities : UTF-8 encoding support, improved syntax highlighting, the ability to copy text without cutting it, the ability to print every character that was pressed on the keyboard, repeat the last search w / o query (Meta key + W / Ctrl + W), spell check / replacing only the selected area of \u200b\u200btext, right shift of the selected text, moving to the beginning and end of a paragraph, searching in the shell of the file manager, converting files of different formats automatically one to one.

The main commands in nano are:

  1. to invoke the full hint directory -CTRL + G or F1 ;
  2. to leave the program -CTRL + X or F2 ;
  3. to write the next file - CTRL + O or F3 ;
  4. to insert the file into the next - CTRL + R or F5 ;
  5. to search for text in the next file -CTRL + W or F6 ;
  6. to replace text in the next file -CTRL + \\ (F14 or Meta + R) ; first, the replacement text is entered, then, after pressing Enter, the replaced text;
  7. to migrate to the preview screen -CTRL + Y (F7 or PgUp) ;
  8. to migrate to the upcoming screen -CTRL + V (F8 or PgDwn) ;
  9. CTRL + K (F9) \u003d deleting (Cut, cut) the line at the cursor position, saving it in the buffer (cutbuffer);
  10. to insert the content of the cutbuffer into the line at the marker position CTRL + U - (F10) ; if the latter has not changed, it performs the role of Undo, which is not normally provided; can also be used for unlimited cloning of lines in an arbitrary part of the text - you just need to move the cursor to the desired place after deleting;
  11. to display information about the cursor position in the form -CTRL + C (F11) ;
  12. to check spelling (using an external spelling program, if it is installed and the corresponding option is enabled in the config, see below) -CTRL + T (F12) ;
  13. to migrate marker (cursor) one line up - CTRL + P ;
  14. to migrate the marker one line down -CTRL + N ;
  15. to migrate the marker one character forward -CTRL + F ;
  16. to migrate the marker one character back -CTRL + B ;
  17. to migrate the marker to the beginning of the next line -CTRL + A ;
  18. to migrate the marker to the end of the next line - CTRL + E ;
  19. to redraw the next screen -CTRL + L ;
  20. to select (and place in the buffer) text, starting from the next cursor position - CTRL + ^ (Meta + A) ;
  21. to eliminate the character at the marker position -CTRL + D ;
  22. to eliminate the character to the left of the marker -CTRL + H ;
  23. to insert a tab character -CTRL + I ;
  24. to autocomplete the next paragraph - CTRL + J (F4) ;
  25. to insert a line feed (CR) character at the marker position -CTRL + M ;
  26. to jump to a predetermined line number - CTRL + _ (F13 or Meta + G) .

As we wrote above, using the Meta key you can also execute commands. List of the following commands with Meta:

  1. to connect i / disable permanent marker position -Meta + C ;
  2. to connect i / disable auto margins -Meta + I ;
  3. to connect i / disable suspension - Meta + Z ;
  4. to connect i / disable output zone prompt -Meta + X ;
  5. to connect i / disable pico editor emulation mode - Meta + P ;
  6. to connect i / disable wrap mode - Meta + W ;
  7. to connect i / disable mouse support (only when building with gpm support - Meta + M ;
  8. for the command enable / disable cut to the end - Meta + K ;
  9. to connect i / disable the use of regular expressions (regexp) -Meta + E .

There is also a command that will remove absolutely everything on your PC. Be vigilant and never execute commands that you do not know. Check out the combination rm -rf / and equivalent to it: echo “test… test… test…” | perl -e ‘$ ?? s:; s: s ;; $? :: s ;; \u003d] \u003d\u003e% - (<-|}<&|`{;;y; -/:

,

The days when Linux was a puzzle for beginners are long gone. Most popular today Linux -distributions have a convenient and intuitive graphical interface, as well as the standard programs supplied with them. But there are also exceptions. Text editor Nano, for example, does not have GUI using the command line interface instead. What is it for if there is gedit?

Nano used mainly in server rooms Linux, it is convenient when editing configuration files and, if you have decided to master the terminal, along the way it will be highly desirable to master and Nano... There is nothing particularly complicated in this, of all console text editors Nano is the simplest to use it, you just need to know the basic key combinations used to work with files and text.

Installation and launch

In the latest versions Ubuntu editor Nano is present by default and therefore does not need installation.

To start it, you need to open a terminal and run the command nano ... If the terminal responds with a message "Command not found" or something like that, then it will mean that the editor is not installed. In this case, you will need to install it by running the following command in the console right there:

sudo apt-get install nano

To start the editor, one command is enough - nano ... This will create a new file in the current directory. To determine which folder is the current one, you can use the command pwd in the terminal. If you need to open a specific file, specify its name, and if it is located in a folder other than the current one, add the full path to it, as shown in the example of the second command:

nano hello.tхt
nano /home/kompick/hello.tхt

As for the config files, when opening them after nano should add a key -w, this is important because it disables line wrapping, which is not used in system files. The editor interface is represented by a console window, at the top of which the version of the program and the name of the current file, as well as the status (whether it was changed or not) ... At the bottom of the window there are two lines showing the most frequently used key combinations. The status bar is also displayed at the bottom, which displays various messages and fields for commands, for example, the F6 button starts a text search.

Basic principles of working with the Nano editor

Hotkey designations may confuse a novice user a little, but this is only at first. Symbol (^) means Ctrl key and (M) Meta - Alt or Esc key. All this can be found in the built-in help nanoby pressing ^ + G, that is, Ctrl + G.

You can use the arrow keys to move through the content, to save changes - Ctrl + O followed by entering Y to confirm and N to cancel. At the time of saving, the editor asks for the file name, which must be entered in a special field at the bottom of the window.

To undo changes made to an unsaved file, press Ctrl + C. For cutting entire lines and paragraphs into nano the combination Ctrl + K is responsible, for their insertion - Ctrl + U. To select certain line items, use Ctrl + 6 or Alt + A, to call the search line - Ctrl + W or F6. Commands Ctrl + A and Ctrl + E allow you to quickly move to the beginning and end of a line, commands Ctrl + Y and Ctrl + V - scroll the contents of a text file up and down. Finally, Ctrl + X is used to exit the editor to the terminal.

But all this is only part of the functionality. nano... The editor supports counting words, lines and characters, working with several files at once, creating backup copies of edited documents, using the mode "only for reading", enable partial mouse support, describe the syntax for highlighting, change the tab width, enable autosave on exit, and much more. Additional parameters are set mainly when starting the editor, but some, for example, the key responsible for the backup -b can be used when saving a file.

Additional features nano it is worth noting the customization of the appearance of the console window.

Editor nano is a console text editor. Almost all Linux distributions have it, macOS, and can be run under Windows. nano is often used to edit configuration files when there is no graphical interface.

The nano is controlled from the keyboard using hot keys... At the bottom of the editor, there is a list of basic keyboard shortcuts. The ^ character stands for the Ctrl key. For example, ^ X stands for the keyboard shortcut Ctrl + X. The case is ignored; the combination Ctrl + X is equivalent to Ctrl + x.

Let's look at how to perform the basic steps when working with nano.

Create a new file

To create a file, you just need to start the editor without parameters. When you close the editor, you will need to enter a file name.

You can also specify the name of the new file immediately:

After executing the command, the nano editor will start and a new empty file will open for editing.

Open an existing file for editing

To edit an existing file, you need to start the nano editor and specify the path to the file you want to open:

Saving changes

Save and continue working

A message will appear in the status bar: File Name to Write: filename (if the file name is absent, then you need to enter the file name). Press Enter to save your changes.

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. You will be prompted to enter a file name. Type 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 the changes, use the keyboard shortcut:
Ctrl + X

There is a question " Save modified buffer ..?", press n.

Copy and paste

Copying and pasting lines

To cut out the whole line and place it in the buffer, move the cursor to the required line and press:
Ctrl + K

To insert line from buffer press:
Ctrl + U

Copying and pasting free text

To copy arbitrary text to the clipboard, you must first select it. To start selection place your cursor at the beginning of the text you want to copy and press:
Ctrl + 6

Move the cursor, the text will be highlighted.

To copy selected text to clipboard, press:
Alt + 6

or to cut out highlighted text, press:
Ctrl + K

Move the cursor to the location where you want to paste the text from the clipboard. To insert text from clipboard press:
Ctrl + U

Search text

To search for text within a file, use the keyboard shortcut:
Ctrl + W

You need to enter a search string and press Enter.

The cursor will be positioned on the first occurrence of the search text (relative to the cursor). To go to the next entry, press:
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 search text. Enter the search string and press Enter.
You will then be prompted to enter the text to be replaced. Enter a string and press Enter.
Next, you will be prompted to replace the found occurrence of the search 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 the found occurrences of the search string.

Hotkeys

To display information on all hotkeys, use the Ctrl + G combination.

The most commonly used nano keyboard shortcuts are:

HotkeysDescription
Ctrl + AMove the cursor to the beginning of the line.
Ctrl + EMove the cursor to the end of the line.
Ctrl + YMove cursor 1 page up (analogue of PageUp)
Ctrl + VMove cursor 1 page down (analogue of PageDown)
Ctrl + _Go to a specific line (you will need to enter a line number).
Ctrl + CShow on which line and at which position the cursor is.
Ctrl + WSearch for text in a file. You must enter a search string.
Ctrl + \\Find and replace text in a file. The search string is entered first, followed by the replacement string.
Ctrl + DDelete the character under the cursor.
Ctrl + KDelete the current line.
Ctrl + OSave changes without closing the editor.
Ctrl + XExit the editor. If the file has been modified, you will be prompted to save the changes.

Something else

There are a couple more interesting tricks when working with nano that not everyone knows about.

Ctrl \u003d Esc Esc

Instead of the Ctrl key, you can double-click the Esc key. For example,
Esc + Esc + X
This is equivalent to the shortcut Ctrl + X.

Only for reading

To open the file for read-only use the -v switch:

File backup

You can make a backup copy of the file when you change it. To do this, use the -B switch:

If you modify the file and save the changes, then a backup copy of the file will be created, with the contents of the file that was before the change. The name of the backup is the same as the original file with a tilde ~ at the end.

Nano Is a command line text editor that comes preinstalled 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, simple search, and many more.

Installing Nano Editor on Linux

If for any reason nano not yet installed on your Linux distribution, you should easily install it with 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 combinations are very easy and visible when editing a file. They automatically change depending on what actions you take.

One thing you should know is that the key combination with the image ^ and the symbol (for example ^ W) is a combination of the Ctrl key and this symbol (Ctrl + W in our example).

A combination that starts with M as shown means that it must be completed by pressing the Alt key followed by the next character.

Below are the options you will see when you first open nano :

  • G Get help
  • ^ O To write
  • ^ W Where
  • ^ K Cut text
  • ^ J Align
  • ^ C Current position
  • M-U cancel (back)
  • ^ X Output
  • ^ R Read file
  • ^\ Replace
  • ^ U Split text
  • ^ T Check spelling
  • ^_ Go to line
  • M-E cancel (forward)

You do not need to memorize each option, as it is always in front of you. You can get a complete list of keyboard shortcuts by pressing ^ G (or press F1) which will open the nano help menu. You will notice that some shortcuts can be used with one key.

For example, F1 key for help or F2 key to exit nano.

Nano Editor Keyboard Shortcuts

Creating a new file in Nano

Creating a new file is as easy as starting nano:

This will open the editor and, after saving the file, it will ask you for a name with which the new file will be saved.


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 navigate to an exact line or column. Nano lets you do this with:

$ nano + line, columns file

For example:

$ nano +3.2 ~ / .bashrc

Will open your .bashrc file and the cursor will be positioned 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, in nano no need to switch to edit mode. You can use the arrow keys on your keyboard to move the cursor around the file.


Editing a file in Nano

Searching for text in Nano

You can search for text within a file using ^ W, which represents the " where". This will open up a search box above the menu, where you can enter the text you are looking for:


Searching for text in Nano

You will 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.

  • Regular Expression Search - press M-R (Alt + R keys) and enter your query with the regular expressions you want to use.
  • Go to line - press ^ T (Ctrl + T) and then the line you want to move the cursor to.
  • 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 to be used for replacement. Finally, you will be asked if you want to replace the matching instance of your search or all matches. If you choose No, the cursor will move to the next match.
  • Move to first line - press ^ Y (Ctrl + Y).
  • Move to the 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 text, press Ctrl + ^, then use the arrow keys to move the cursors.

  • To copy the selected text, press Alt + ^.
  • To cut the 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 into Nano

Save file to Nano

If you want to save the current changes to the file, press ^ O (Ctrl + O). If you are editing a new file, you will be prompted for a name for this 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 want 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 conjunction with the -C option to tell nano where to store these backups as shown in the example:

$ nano -BC ~ / backups myfile.txt

The above steps will back up the file myfile.txt in folder " backups"Located in the user's home directory. Note that the backup directory must be existing, 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 been saved yet, you will be prompted to save your changes with yes / no or cancel the exit.

Output

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.

For beginners who are just starting to learn Linux, the terminal is a lot of stress, but when it comes to the nano command ...

Almost all servers running Linux, including Ubuntu Server, do not use a graphical shell; all settings are made using the terminal. In desktop Linux distributions, the situation is slightly simpler, but still, if you want to fine-tune the system, then familiarity with the terminal is inevitable. One of the hardest "commands" to master is Nano Linux. This command, " nano “Is nothing more than a console text editor.

How to use Nano text editor in Linux terminal

In this article, we will try to tell you in an accessible way how to use this text editor so that Linux does not seem such a complex operating command.

Installing Nano on Linux

If the terminal does not react to the nano command in any way, then this text editor is not installed. To install it, enter the command:

sudo apt install nano

Everything is ready to go!

Launching Nano

Text editor nano only works in the terminal. One more clarification, before you start, the Linux operating system is case sensitive, if a word or part of a command is capitalized, you need to type it that way, otherwise you will get an error.

If you are in the directory (folder) where the required text file is located, then, in order to start editing it using nano you need to write in the terminal like this:

Nano index.html

By the way, the command will help you find out which directory you are currently in. pwd , and which files are nearby ls .

If we edit a file that is located in another directory (folder), then you need to specify the full path in the terminal:

Nano /var/www/html/index.html

If you suddenly edit a file sensitive to word wrapping, then enter the command in the terminal nano with additional key -w :

Nano -w /var/www/html/index.html

To open a document on a specific row or column nano + row, the file_name column

For example nano +3,2 / etc / hosts

Nano keyboard shortcuts for text editor control

With the input of text information in nano no one should have a problem. But how convenient it is to manage text data, delete in bulk, move, and most importantly, how to save it to nano, many have problems with this.

Action name Nano hotkeys
Open a file on a specific line

+ line_number

For example:

nano +25 log.txt

"Slow" movement to the sides - up, down, left, right Keys

or

Ctrl F and Ctrl B

←→ or

Ctrl P and Ctrl N

Move to the beginning of the file Alt | or Alt \\
Move to the end of the file Alt / or Alt?
Move a word forward Ctrl Space
Move to the beginning of a line Ctrl A
Move to end of line Ctrl E
Move one word back Alt Space
Move one line by number Alt G or Ctrl -
Next page (if long text file) Ctrl Y
Previous page (if long text file) Ctrl V
Cut "delete" the entire line Ctrl K
Erase everything from cursor to end of file ALT T
Paste a previously cut or copied line Ctrl U
Select part of the text copy or cut it (or delete) Navigate to the required section of text

Pinch ALT A

and move the keys ↓←→

Copy Alt-6

Cut or delete Ctrl K

Insert tab Ctrl I
Paste text information from another file Ctrl R

specify the path to the file

In nano, show row and column numbers CTRL C
Find the required word in a text file Ctrl W

write the desired word

Find Next Ctrl W
Saving the changes made to the file Ctrl O

to push Enter

Save the changes made to a file and exit the nano editor Ctrl O

hit enter

Don't save your changes Ctrl Z
Save changes and rename the file Ctrl X

to push Y

enter a new filename

to push Enter

Hopefully using the nano terminal text editor won't be as much of a headache now!

Do you still have additional questions? Write them in the comments about what you did or vice versa!

That's all! Read more articles and instructions in the section. Stay with the site, it will be even more interesting further!