Nano how to save and exit

Nano how to save and exit

How to Save and Exit in Nano Editor? [A Beginner’s Guide]

This tutorial is a guide for all the beginners who want to use save and exit commands in nano editor.

List of content you will read in this article:

Nano is the most fundamental, command-line-based text editor for Linux. It has all common text editor features, including highlighting syntaxes, multiple buffers, scanning and replacement with regular expression support, type corrections, and UTF-8 encoding. You can easily save and exit in the nano editor through the command-line options given in this tutorial.

You must have the write permissions on the file to save it. You must have written permission to the directory where the file would be generated while making a new file in the nano editor to save the file.

Linux VPS

Some Useful Nano Editor Commands

Any command prefixed with a caret symbol (^) means to use the Ctrl key (e.g., ^G means to press the Ctrl+G keys at the same time).

Here we have listed the top nano editor command which you should know:

Conclusion

Using the command Ctrl+O and Ctrl+X, you can easily save nano file and exit a file in a nano editor. But be careful; you must have the write permission to do these for all the files and directories you are working on, and then only will you be able to make any changes in the nano editor. Hence in this way, we can save and exit in the nano editor using the command line.

2) Add the line I need

3) now I don’t know how to Save and Exit

I thought it is :w + enter. If this is correct I need some direction to use it.

Nano how to save and exit. Смотреть фото Nano how to save and exit. Смотреть картинку Nano how to save and exit. Картинка про Nano how to save and exit. Фото Nano how to save and exit

7 Answers 7

No, :w is a /usr/bin/vi command. Use the combination control + x to exit. You will be prompted to save the file if you have made unsaved changes.

Nano is intended to be a bit friendlier / simpler to new users than vi/vim or emacs which both cater to more power users that have spent time learning how to use them effectively.

Nano how to save and exit. Смотреть фото Nano how to save and exit. Смотреть картинку Nano how to save and exit. Картинка про Nano how to save and exit. Фото Nano how to save and exit

If you accidentally confirmed that you want to save the file but you actually don’t, you can always cancel by pressing Control + C when you’re prompted for a filename.

Nano how to save and exit. Смотреть фото Nano how to save and exit. Смотреть картинку Nano how to save and exit. Картинка про Nano how to save and exit. Фото Nano how to save and exit

I just have the same question. after a lot of trail and error i learned that Nano is asking you to write the name of the «new conf file». Since you do not want a new file just hit enter indicating to nano that you want to keep the same name.

Basically you change the conf file, pres Ctrl + x and finally hit Enter (to indicate the same name). Good luck

Nano how to save and exit. Смотреть фото Nano how to save and exit. Смотреть картинку Nano how to save and exit. Картинка про Nano how to save and exit. Фото Nano how to save and exit

Hey I got something for you guys just enter ctrl + x and when it says to save press ‘Y’ if you want to save Then just press enter button Hope it works 🙂

To open your file instead. This will create your file if it doesn’t exist, or open it for editing.

Ubuntu Documentation

Introduction

GNU nano is a simple terminal-based text editor. Though not as powerful as Emacs or Vim, it is easy to learn and use. Nano is ideal for making small changes to existing configuration files or for writing short plain text files. It was originally created as a free replacement for the non-free Pico editor. Pico is the terminal-based editor used in the Pine email suite from the University of Washington.

Nano can be used in a terminal window or at the system console.

Basic use of nano is covered here. If you want to learn more advanced techniques such as the use of multiple buffers or syntax highlighting of code, see the the nano project’s documentation.

Installing Nano

Nano is part of the standard Ubuntu installation, and should be on your system already. If for some reason it’s not, use your favorite package manager to install nano.

Using Nano

Nano is a terminal-based command-line program. Although not complicated or difficult to use, it is different than a GUI-based text editor such as gedit. The two main features that differ are the short-cut key combinations and the use of a mouse.

Note

This discussion refers specifically to the use of nano in a terminal window. Using nano at the system console is almost identical, with the main difference being the use of the mouse.

Starting Nano

To start nano with an empty file, open a terminal window and at the command-line type «nano» (without the quotes). For example:

nano

In the above example, if the file .bash_history does not exist in your current directory, nano will start a new blank file and use .bash_history as the name for it.

Caution

Line wrap is on by default. When line wrap is on, nano inserts end-of-line characters into your file when it wraps lines to fit the width of the terminal window. Only lines that you type or paste into the window are wrapped. Existing long lines are not wrapped until you add new text to the line or use the Ctrl+J key combination to justify the current paragraph.

Screen Layout

Figure 1: Default nano screen layout

Nano how to save and exit. Смотреть фото Nano how to save and exit. Смотреть картинку Nano how to save and exit. Картинка про Nano how to save and exit. Фото Nano how to save and exit

The default nano screen layout is as shown in Figure 1. The bottom two lines show the key combinations for common operations. The ^ symbol represents the Control key on your keyboard. For example, use the Ctrl+G key combination to display a basic introduction to nano and its default screen layout.

The screen fonts and background colours are determined by your terminal settings. And when you resize the terminal window, nano adjusts itself accordingly.

Using The Mouse

By default, mouse services are provided by the terminal window. The mouse works almost the same as in a GUI editor. You can highlight text, right-click to copy and paste, and use the middle mouse button for pasting text from the buffer. However, when you use the middle mouse button to paste text, the text is pasted at the current cursor location, not at the mouse pointer location. Other limitations exist. For example, you cannot use the mouse to cut or delete text, nor can you use the mouse to scroll through the file.

Nano has its own built-in mouse services, but they are limited. They provide only the ability to move the cursor to the point where you click, and to mark the beginning and end of a section of text. Use the Alt+M key combination to toggle between using the terminal’s mouse services and nano’s built-in mouse services.

Note

If you are using nano at the system console, you must have gpm installed and running before using the mouse. The gpm package is in the Universe repository.

Using the Keyboard

Typing at the keyboard will insert text at the current cursor location. The Page Up and Page Down keys, the Arrow keys, and the Insert key and Delete key all work as in most other text editors. If you are at a keyboard that does not have these keys, you can use alternative Ctrl+key combinations. They are listed in nano’s online help, accessible with the Ctrl+G key combination.

Copy, paste, and cut operations are available, but they do not use the same Ctrl+key sequences as in most GUI editors. See the Editing Text section for more information.

Opening, Saving, and Closing Files

You can open a file for editing when you start nano, as discussed in the Starting Nano section. This section shows you how to open a file when nano is already started.

Opening Files

Open a file with the Read File command, Ctrl+R. The Read File command inserts a file from disk at the current cursor location.

When prompted, type the name of the file you want to open, or use the Ctrl+T key combination to use nano’s built-in file browser to navigate to the file you want to open.

If a file is already open, nano will insert the new file into it at the current cursor location; it will not close the existing file, nor will it open a new screen for the new file.

Save and Save As

Save and Save As are both accomplished with the Write Out command, Ctrl+O.

When prompted, press enter to accept the existing file name. To save as another file name, type in the new name and press Enter, or use the Ctrl+T key combination to use nano’s built-in file browser.

Closing Files

Close a file with the Ctrl+X key combination. If the file you are working on has been modified since the last time you saved it, you will be prompted to save the file first. Type y to save the file, or n to exit nano without saving the file.

Closing a file also closes nano.

Editing Text

As is normal in most text editors, text that you type into nano is inserted at the current cursor position. The Delete and Backspace keys also work the same as in other editors.

Use the Alt+6 key combination to copy text to the «cut buffer». Similarly, use the Ctrl+K key combination to delete text (it is cut to the «cut buffer»). If no text is marked, these two commands copy or cut the entire line of text.

Use the Ctrl+U key combination to paste the text in the «cut buffer» into the file.

To cut or copy specific text, you must first mark the start and end points of the text you want to select. You can do this with the either keyboard or the mouse, but to use the mouse for marking you must first turn on nano’s built-in mouse services.

To use the keyboard to select text, move the cursor to the start of the text you want to select, press the Alt+A key combination to mark the start, then move the cursor to the end of the section you want to select.

To use the mouse to mark the start of a selection, first make sure that nano’s built-in mouse services are turned on. Use the Alt+M key combination to toggle between nano’s mouse and the terminal’s mouse. Click on the location where you want to mark the start of the selection, move to the end of the section you want to select, and click the mouse again. You might need to use the keyboard to scroll the screen up or down because nano does not support scrolling with the mouse.

Once you have marked the beginning and end of text, the Alt+6 and Ctrl+K key combinations can be used to copy or cut it, respectively.

Note

Text copied or cut into nano’s internal «cut buffer» can only be pasted back into the current nano session. The text is not available for pasting into other windows or programs.

If you are using nano in a terminal window you can use the mouse to copy and paste text to and from other windows on your desktop. You cannot use the mouse to cut or delete text.

Quitting Nano

To quit nano, use the Ctrl+X key combination. If the file you are working on has been modified since the last time you saved it, you will be prompted to save the file first. Type y to save the file, or n to exit nano without saving the file.

Resources

Basic Introduction to Emacs: EmacsHowto

Introduction to Vim: VimHowto

Using a terminal and the command line: HowToUseTheTerminal and CommandlineHowto

Nano (последним исправлял пользователь fitojb 2022-04-03 19:47:01)

The material on this wiki is available under a free license, see Copyright / License for details
You can contribute to this wiki, see Wiki Guide for details

How to Use Nano to Edit Files

There are several text editors for the command line, but nano is probably the easiest to use.

Editing files at the command line can save you time as you don’t need to download the files, edit them locally, and then upload them back to the server. Instead, you can just edit files directly on your server.

To make a backup of a file, use the cp («copy») command:

The above command creates a copy of the file in the same directory as the original file.

How to Open a File in nano

First, log into your server using SSH. If you are editing an app’s files, log in as the app’s system user. If you are editing system files, you will need to log in as root.

Once you’ve logged in, you can open a file in nano by typing:

Using nano

Your terminal screen will now show the nano interface and the the contents of the file you’re editing. At the bottom of the screen, you will see a list of commands (shortcuts) you can execute:

Nano how to save and exit. Смотреть фото Nano how to save and exit. Смотреть картинку Nano how to save and exit. Картинка про Nano how to save and exit. Фото Nano how to save and exit

You’ll only need to use a few of these commands.

The caret («^«) means the CTRL key. So, ^G means CTRL+g.

The biggest difference between nano and other editors is you can’t use your mouse. Instead, you use your arrow keys, Home, End, Page Up, and Page Down to move the cursor around the page.

Using the arrow keys, move the cursor to the text you wish to change, then begin typing or erasing as you would normally in any text editor.

Getting Help

You can type CTRL+g to bring up useful Help Documentation. Use your arrow keys or the shortcuts to scroll through the documentation.

Nano how to save and exit. Смотреть фото Nano how to save and exit. Смотреть картинку Nano how to save and exit. Картинка про Nano how to save and exit. Фото Nano how to save and exit

Press CTRL+x to exit the help documentation and return to editing your file.

Searching

To search for a word or string in the file, press CTRL+wwhere is») and nano will prompt you to enter what you’re looking for:

Nano how to save and exit. Смотреть фото Nano how to save and exit. Смотреть картинку Nano how to save and exit. Картинка про Nano how to save and exit. Фото Nano how to save and exit

This search is not case-sensitive. Searching for «DATAbase» will find the same strings as searching for «database».

Saving Your Work

You can save the file you’re editing by typing CTRL+o («write out»). You will be prompted for the name of the file to save. If you wish to overwrite the existing file, just press ENTER. If you want to save to a different filename, type in the different filename and press ENTER.

When you’re done, exit nano by typing CTRL+x. Before exiting, nano will ask you if you wish to save the file:

Nano how to save and exit. Смотреть фото Nano how to save and exit. Смотреть картинку Nano how to save and exit. Картинка про Nano how to save and exit. Фото Nano how to save and exit

Type y to save and exit, type n to abandon your changes and exit.

If you have difficulty holding CTRL and pressing another key at the same time, you can instead press and release the ESC key twice and then press the other key. In other words, the key sequence:

works the same in nano as:

If you only want to view a file, not edit it, you can open the file in read-only mode with the -v argument:

The -v means «View mode.» If you try to make any changes while in view mode, you’ll see the message «Key is invalid in view mode.»

Nano how to save and exit. Смотреть фото Nano how to save and exit. Смотреть картинку Nano how to save and exit. Картинка про Nano how to save and exit. Фото Nano how to save and exit

Where to Learn More

For most users, this tutorial covers all you’ll want to know. If you’d like to learn about more of nano‘s features, check out the official documentation.

Как сохранить файл в nano Linux

В этой небольшой статье мы рассмотрим как сохранить файл в nano Linux. Это может понадобится если вы уже отредактировали конфигурационный файл и хотите сохранить изменения.

Как сохранить изменения в nano

1. Обычное сохранение

Здесь всё делается довольно просто. Для того чтобы сохранить изменения после завершения работы с файлом необходимо нажать сочетание клавиш Ctrl+O. В принципе об этом написано в нижней части окна программы. Здесь перечислены все сочетания клавиш, которые вы можете использовать. Тут знак ^ означает Ctrl:

Nano how to save and exit. Смотреть фото Nano how to save and exit. Смотреть картинку Nano how to save and exit. Картинка про Nano how to save and exit. Фото Nano how to save and exit

После нажатия этого сочетания клавиш редактор попросит ввести имя файла для сохранения:

Nano how to save and exit. Смотреть фото Nano how to save and exit. Смотреть картинку Nano how to save and exit. Картинка про Nano how to save and exit. Фото Nano how to save and exit

Когда всё будет готово, достаточно нажать Enter. Если вы передумали сохранять документ и хотите вернутся к редактированию в этом окне нужно нажать Ctrl+X. После сохранения программа сообщит, что файл успешно сохранён:

Nano how to save and exit. Смотреть фото Nano how to save and exit. Смотреть картинку Nano how to save and exit. Картинка про Nano how to save and exit. Фото Nano how to save and exit

Теперь вы можете закрыть редактор нажав сочетание клавиш Ctrl+X.

2. Сохранение если нет доступа на запись

Однако, если вы попытаетесь сохранить данные в файл, принадлежащий другому пользователю или суперпользователю, к которому у вас нет доступа (например, файлы конфигурации в директории /etc), то получите ошибку: «Ошибка записи /имя/файла: Отказано в доступе«:

Nano how to save and exit. Смотреть фото Nano how to save and exit. Смотреть картинку Nano how to save and exit. Картинка про Nano how to save and exit. Фото Nano how to save and exit

Проще всего, закрыть редактор, нажав Ctrl+X не сохраняя изменений. На вопрос редактора про сохранение буфера надо ответить No:

Nano how to save and exit. Смотреть фото Nano how to save and exit. Смотреть картинку Nano how to save and exit. Картинка про Nano how to save and exit. Фото Nano how to save and exit

А затем открыть редактор уже от имени суперпользователя:

sudo nano /etc/passwd

После этого вы сможете записать данные в файл как было описано выше. Если изменения не хочется терять, во время запроса имени файла можно указать путь к новому файлу в вашей домашней директории, например,

Nano how to save and exit. Смотреть фото Nano how to save and exit. Смотреть картинку Nano how to save and exit. Картинка про Nano how to save and exit. Фото Nano how to save and exit

Новый файл сохранится туда, потом вы сможете переместить его вместо старого в помощью команды mv уже используя sudo:

Не забывайте, что все системные файлы необходимо редактировать от имени суперпользователя.

Выводы

В этой небольшой статье мы рассмотрели как сохранить изменения в nano при обычном использовании редактора, а также если вы забыли использовать sudo для редактирования системных файлов. Как видите, всё довольно просто. В принципе, если файл нельзя редактировать, то в нижней части окна редактора выводится об этом сообщение. Будьте внимательны. Если у вас остались вопросы, спрашивайте в комментариях.

Источники информации:

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *