0
0
Linux CLIscripting~5 mins

nano text editor in Linux CLI - Commands & Configuration

Choose your learning style9 modes available
Introduction
Sometimes you need to quickly create or edit a text file on a Linux system. Nano is a simple text editor that runs in the terminal and helps you do this easily without complicated commands.
When you want to quickly write a configuration file on a server without a graphical interface
When you need to edit a script or note directly from the command line
When you want a simple editor that shows commands at the bottom for easy use
When you are new to Linux and want an easy way to edit files without learning complex editors
When you want to make quick changes to text files during troubleshooting or setup
Commands
This command opens the file named example.txt in the Nano editor. If the file does not exist, Nano creates a new empty file with that name.
Terminal
nano example.txt
Expected OutputExpected
No output (command runs silently)
Inside Nano, pressing Ctrl+O saves the current file. You will be asked to confirm the file name before saving.
Terminal
Ctrl+O
Expected OutputExpected
File Name to Write: example.txt
Pressing Ctrl+X exits Nano. If there are unsaved changes, Nano will ask if you want to save before quitting.
Terminal
Ctrl+X
Expected OutputExpected
Save modified buffer (ANSWERING "No" WILL DESTROY CHANGES) ?
This command shows the contents of example.txt in the terminal to verify your changes.
Terminal
cat example.txt
Expected OutputExpected
Hello, this is a test file. This line was added using Nano.
Key Concept

If you remember nothing else from Nano, remember: Ctrl+O saves your file and Ctrl+X exits the editor safely.

Common Mistakes
Trying to save the file by pressing just Enter or Escape
Nano requires Ctrl+O to save; pressing Enter or Escape alone does not save changes.
Press Ctrl+O to save, then Enter to confirm the file name.
Exiting Nano with Ctrl+C or closing the terminal without saving
This causes loss of any unsaved changes.
Always use Ctrl+X to exit and save changes when prompted.
Summary
Use 'nano filename' to open or create a text file in Nano editor.
Press Ctrl+O to save your changes and Ctrl+X to exit Nano.
Use 'cat filename' to view the file contents after editing.