Linux Command Line Syntax: The nano Command
Nano was created in 1999 by Chris Allegretta to be a GPL-released replacement for the non-GPL’d Pico text editor. Nano is a keyboard-centric text editor where all functions are controlled by keys and key combinations. This makes Nano an incredibly efficient editor. Instead of having to reach back for your mouse, your fingers take care of all commands on the keyboard.
The Nano editor works from the command line (you’ll need a terminal emulator such as aterm, eterm, gnome-terminal, or konsole). You start Nano with the command nano. When Nano is open you will have a nearly empty screen, save for a listing of some of the keyboard commands listed at the bottom.
When using the Nano editor, the Ctrl key is your friend. As you can see, in the screenshot above, there are a few of the main commands listed at the bottom. Each of those command letters is preceded by the “^” character which is the Ctrl key. So if you see “^X” that means Ctrl-X together. The other character to remember is the “M” character which represents the Esc key. If you see the combination Md that actually means Esc-d together.The most useful commands for Nano are:
^x - Close Nano (You will be prompted to save.)
^o - Save without quitting
^c - Line number
^k - Cut
^u - Paste
^t - Spellcheck
^c - Cancel
Md - Word count
Mi - Insert a tab at the cursor position
Starting a new file and opening a file
There are a few ways to deal with a file in Nano. Say you know the name and location of a text file to edit (we’ll use fstab as an example.) To open /etc/fstab with nano you would enter the command nano /etc/fstab and the file would open. If you already have Nano open to a blank file you can hit the ^r combination which will prompt you for the file to read into the current buffer. The “read into” ability of Nano is very helpful for appending at the end of a file. If you have multiple text files that you want to combine into one larger file you can open up the first, read the second into the end of the first, and then read the third at the end of the second.
When you open a new (blank) file you can start it by either typing in nano and then, when you close, you can give the file a name. Or you can issue the nano command with the new file name and then when you close and save the file, the name will already be chosen.
Although not quite as powerful as the “big two” (emacs and vi), Nano is an amazingly simple editor to use. Once you start using Nano to edit text and configuration files, you will most likely never use another editor again.
This post is part of the series: Linux Command Line
If you ever plan on doing any administration on a Linux machine, you would be well served to get to know the command line interface. In this Bright Hub series you will be introduced to various concepts surrounding one of the most powerful admin tools around.
- Linux Command Line: Introduction
- Linux Command Line: ls
- Linux Command Line: cd
- Linux Command Line: mkdir
- Linux Command Line: df
- Linux Command Line: ln
- Linux Command Line: top
- Linux Command Line: mount/umount
- Linux Command Line: Cron/Crontab
- Linux Command Line: chmod
- Linux Command Line: wget
- Linux Command Line: cat
- Linux Command Line: grep
- Linux Command Line: dd
- Linux Command Line: sudo
- Linux Command Line: startx
- Linux Command Line: adduser
- Linux Command Line: at
- Linux Command Line: aterm
- Linux Command Line: nano
- Linux Command Line: hostname