In this practical example I'm going to edit my conky configuration file, so that Conky displays upload/download information for the internet connection that the computer is currently using. Conky is a lightweight system monitor that can be used to display just about anything. Nick on this forum recommended that I should install it if I want to find out more about how my computer works, and after having used it for a few months I would also recommend it to others for the same reason. There are many versions of Conky, but I just have the basic (most lightweight) version which I've modified slightly (which is very easy to do) and which you see in the screenshots below.
First of all I'll pretend I don't know where the file is so that I can also demonstrate the extremely useful "locate" command. (EDIT: Before you use locate, please refer to bmike1's advice in post #2) The file I want to edit is called conky.conf, so I open a terminal and type "locate conky.conf" then press Return:
The top search result is the file and its path, which I have highlighted. Now, a command that you might find on the internet to open this file for editing purposes could be:
gksu gedit /etc/conky/conky.confTo run that command, you would have to install both gksu (which in this instance would allow the file to be edited by the root user using a GUI text editor) and gedit (which is a GUI text editor) if you didn't already have them installed. But there is no need to install either when you know how to use nano, or any other command line text editor for that matter.
So in order to open and edit the file in nano instead of gedit, what you would do is use "sudo" instead of "gksu" and type "nano" instead of "gedit", then run the command as follows:
sudo nano /etc/conky/conky.conf
After entering my password and pressing Return, the file opens in nano:
Simply use the up/down/left/right keys on your keyboard to scroll down to the text you want to edit, positioning the cursor one space to the right of the last character of any text you want to delete. In this instance I'm going to change "eth0" to "usb0"
Simply use the backspace key to delete any text you want to delete, then type in the new text.
When you are finished typing, hold down Ctrl and press x on your keyboard, and a message will appear asking if you want to save the changes to this file.
Type y for yes, then:
..press Return to confirm that you want to save the changes to this file, then nano will close and you will be back at the command prompt:
That's all that there is to editing a file using nano, and as you can see my conky is now doing what I wanted it to do.
Edited by Al1000, 17 December 2014 - 06:53 PM.