You can use it in combination with the -C option to tell nano where to save those backups like this: $ nano -BC ~/backups myfile.txt You can use nano’s -B option, which will create backup of the file you are editing. Sometimes when editing a file, you may want to keep temporary copies of the same file just in case. This will save your current changes and nano will remain opened so you can continue making changes to the file. If you are editing a new file, you will be asked to give that file a name. If you wish to save your current changes to the file, press the ^O ( Ctrl + O) combination.
You can search for text inside a file by using ^W, which represents the “ where is” option. Edit Files in Nano Search for Text in Nano To move the cursor around the file, you can use the arrow keys on your keyboard. Unlike vim, there is no need to switch to edit mode in nano. Upon opening or creating files you can start editing/writing immediately. bashrc file and the cursor will be located on the third line, second column. Nano allows you to do this with: $ nano +line,columns file
Sometimes, you may need to open a file and go at exact line or column. If the file does not exist, nano will try to create it. The above command will try to open the file “ my_text_file.txt” from your home directory. To open a file you can run: $ nano ~/my_text_file.txt Create New File in Nano Open a File in Nano This will open the editor and upon saving the file, it will ask you to give it a name with which the new file will be saved.
Nano Editor Shortcut Keys Create a New File in NanoĬreating new file is simple as running nano: $ nano You will notice that some shortcuts can be used with single key.įor example F1 key to get help or F2 to exit nano.
You can get the full list of keyboard combinations by pressing ^G (or press F1) which will open nano’s help menu. You don’t need to remember each option as it is always in front of you. One thing you should know is that a keyboard shortcut represented with ^ and a symbol (for example ^W) is a combination of the Ctrl key and that symbol ( Ctrl+W in our example).Ī combination that is shown to start with M means that it needs to be completed by pressing Alt key and the following symbol.īelow are listed the options that you will see when you first open nano:
They change automatically depending on what action you are taking. Those combinations are really easy and are visible while you edit your file. Nano uses keyboard combinations for different functions, such as to find text in a file, justify text etc.
If for any reason nano is not already installed on your Linux distro, you should be able to easily install it with the following commands: # apt install nano It has plenty of useful features such as syntax coloring, line numbering, easy search and many others. It is often preferred by new users because of its simplicity, compared to other command line text editors such as vi/vim and emacs. Nano is a command line text editor, that comes preinstalled in almost every Linux distribution.