Top.Mail.Ru

How to save a document in the Nano text editor

How to save a document in the Nano text editor

When you need to quickly jot down a thought, correct a configuration, or sketch out a draft right in the terminal, Nano helps out with its simplicity and clear prompts. It does not require long setup and does not distract with unnecessary windows: open the file, make edits, save and you can move on. 

Next, we will look at how to create a file and save it, and also share useful life hacks for working with the program. 

Creating a file

The easiest way is to start with a command that immediately indicates the name of the future document. If such a file does not exist yet, it will appear when saving; if there is one, it will open for editing.

nano notes.txt            # create or open a file in the current folder

nano ~/docs/todo.md         # file in home directory, docs subfolder

nano /etc/nginx/nginx.conf # system file (usually requires elevated rights)

You can choose any extension or do without it at all — Nano works with plain text and does not impose a format. 

Saving a file

Nano always shows hints at the bottom of the screen. There you will see messages like ^O Write Out and ^X Exit. The ^ character means the Ctrl key, that is, ^O is Ctrl+O, and ^X is Ctrl+X.

A. Normal saving of the current file

If the file already has a name, click Ctrl+O. A line will appear below:

File Name to Write: current_file_name

Confirm Enter. The editor will tell you how many lines have been written (Wrote 42 lines), and you can continue working.

B. “Save as…” — new name or different path

For example, if you need to leave the source intact or move the copy to another folder:

  1. Click Ctrl+O.
  2. In the File Name to Write: field, enter a new name or full path, for example:

    ~/docs/notes_version2.txt
  3. Click Enter. Now you are editing this new copy.

Tip: The Tab key completes paths and names, which is useful for long directory names.

C. Save on exit

Clicked Ctrl+X, and the edits haven’t been recorded yet? In this case, Nano will politely clarify:

Save modified buffer? (Answering «No» will DISCARD changes.)

  • Y — save; then confirm your name Enter or specify something else.
  • N — exit without saving.
  • Ctrl+C — cancel exit and return to editing.

D. The folder has not yet been created

If you try to save to a non-existent directory, a write error will appear. Create the path first, then save again:

mkdir -p ~/docs/reports/September

# Then in Nano: Ctrl+O → ~/docs/reports/September/results.md → Enter

Bonus: a couple of useful life hacks for working with Nano

In everyday use of the Nano, it all comes down to two basic habits: pressing occasionally Ctrl+O → Enter, and at the end — Ctrl+X. This is already enough to not lose changes and keep the process under control.

  • Save upon completion of the logical block. You have written a paragraph — click Ctrl+O → Enter, and the edits are already in the file.
  • Check the path and use autocompletion. Tab reduces the risk of typos in long catalogues.
  • Be careful with system files. sudoedit is safer than direct editing: there is less chance of leaving a half-empty config or violating rights.
  • Look at the status bar. There you can see the file name and key prompts; if the file is modified, Nano will not allow you to quietly exit without asking to save.

CONTENT:

Similar

All news

Похожее

Все новости

Adaxa Suite: подробный обзор ERP-системы корпоративного класса

Adaxa Suite — комплексная ERP-платформа для компаний, которым уже тесно в рамках простых учётных систем, но которые при этом не готовы идти в сторону дорогих корпоративных решений уровня SAP или Oracle. Изначально продукт создавался для среднего бизнеса, которому нужна большой набор функций, сквозная автоматизация процессов и надёжная архитектура без чрезмерной стоимости владения. Архитектура и техническая […]

Как заказать дополнительные IP-адреса на UFO.Hosting: пошаговая инструкция

По мере роста проекта одного IP-адреса может стать недостаточно. Это типичная ситуация для компаний, которые масштабируют инфраструктуру, запускают новые сервисы или разделяют внутренние процессы. В UFO.Hosting подключение дополнительных IP-адресов выполняется через биллинговую панель и занимает всего несколько минут. Важно: возможность для заказа дополнительных IP-адресов доступна для тарифов VPS начиная с Haedus. Зачем нужны дополнительные IP-адреса […]