How to Use Nano Command Line Text Editor in Linux
Nano is a simple yet powerful command line-based text editor, very popular among beginner Linux users for its simple-to-use interface. As a command-line editor, it offers a lightweight alternative to more complex graphical text editors. In this article, we will explain how you can use the nano text editor in Linux, right from installing it to editing documents with it.
How to Install Nano in Linux
Generally, the nano editor comes preinstalled on mostLinux distros. If you are not sure, you can check using the following command:
nano –version
After executing the command, if you see the nano version number in the Linux Terminal, this means it is installed, and you can proceed to the next section wherein we’ve described how to use the nano editor in Linux. If you get an error like “nano: command not found,” then use the commands below to install nano depending on your distro:
sudo apt install -y nano
sudo yum install -y nano
sudo pacman -S nano
sudo dnf install nano
Nano Command: Syntax and Options
Using the nano command line editor in Linux is pretty straightforward. The basic syntax to use nano text editor is:
In the above syntax, the <file_name> stands for the name of the file you want to create or edit via the Nano command line editor. And for the options, some of the common ones you can pair with the nano command are:
How to Open/ Create a New File with Nano
To open a file with the nano command in Linux, use this syntax:
nano <file_name>
For example, to open the file “test.txt”, use the following command:
nano test.txt
To create a new file with nano, use this command:
nano <file_name>
For example, to create a new file with the name “test.py”, use this command:
nano test1.txt
When the nano command is executed, it first looks for the given file name in the mentioned directory. If the file is found, it opens the file, else creates a new file with the given file name.
How to Edit a File with the Nano Editor
In the Nano command line editor, you can directlystart typing to modify your file, unlike Vim where you have to take care of different modes. You can easily perform operations like cut, copy, paste, and more using the nano command in Linux.
Cut Selected Text
Copy Selected Text
Paste Selected Text
Search and Replace Text in Nano
Sometimes you need to search for some specific text inside a huge document and scrolling through it is not a viable option. Fortunately, the nano command comes with a search-and-replace utility, which can work on documents formatted with Linux, Windows, macOS, etc.
To search for a specific text, press“CTRL + W,”type the text you want to search in the new search bar at the bottom of the screen and hit the Enter key. If found, the cursor will get placed at the beginning of the searched word. To move on to the next occurrence of the searched term, use “ALT + W.”
To search and replace a specific text,press “CTRL + \”on the keyboard. Enter the search term and press enter. Then, enter the term you want to replace it with on the next prompt. The cursor will move to the first position it found the search term.
You can press either ‘y’ to replace this text or ‘n’ to skip the current match and move on to the next one.
To replace all occurrences of the search term with the replace term, press ‘a’ on the keyboard.
The default nano command keybindings are different from the common keybindings, which the users may be accustomed to while working on other Linux GUI apps. To make things easier for beginners, the Nano text editor has a small cheat sheet right at the bottom of the screen (more on it later).
How to Save Files and Exit Nano Editor
How to exit Vimis a question that has been wreaking havoc in the lives of Linux users since its inception, as you don’t get any prompt even for basic tasks such as saving or exiting the editor. However, the nano command provides a small prompt to help users get around.
To save and exit the nano command screen and return back to the Linux shell prompt, simply press “CTRL + X” on your keyboard. If you have made any changes to the file, press ‘y’ to save the changes or press ‘n’ to discard them. You will then be asked if you want to keep the same file name or use a new name. Enter the new file name or press Enter to use the same file name.
To simply save and continue editing the document in Nano editor, press “CTRL + O” on the keyboard. Press the Enter key to use the same file name or enter the new name and then hit enter.
Nano Command in Linux: Keyboard Shortcuts
The nano command in Linux comes with some nifty keyboard shortcuts that you can use to make your workflow much easier. You even get a smaller version of help at the bottom of the screen. Here, the caret symbol‘^’ is read as CTRL, and the ‘M’ character is read as the Meta key or the ALT key.
Here are some of the common shortcuts to use with the nano command that works on all operating systems, including Linux, Windows, macOS, etc:Keyboard ShortcutDescriptionCTRL + AMoves the cursor at the beginning of the lineCTRL + EMoves the cursor at the end of the lineCTRL + YScrolls the screen up by a pageCTRL + VScrolls the screen down by a pageCTRL + GOpens nano command help windowCTRL + OSaves the current fileCTRL + WSearches for a specific text in the entire documentCTRL + KCuts the entire selected portion of text to the clipboardCTRL + UPastes the text portion from the clipboard into the documentALT + 6Copies the selected text to the clipboardCTRL + XExits the editorCTRL + _Lets you go to the specified line and column number.ALT + AUsed to select textCTRL + GOpen help menu for nano
Frequently Asked Questions
The nano editor is a simple easy-to-use command-line text editor, which can be handy for editing text documents on Linux distros.
Compared to Vim, the nano command line editor in Linux has a much easier learning curve and is easy for beginners to use in their daily workflow.
Beebom Staff
Bringing the latest in technology, gaming, and entertainment is our superhero team of staff writers. They have a keen eye for latest stories, happenings, and even memes for tech enthusiasts.
Add new comment
Name
Email ID
Δ
01
02
03
04
05