Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo
- - - - -

How to edit a file using nano text editor


  • Please log in to reply
5 replies to this topic

#1 Al1000

Al1000

  • Global Moderator
  • 6,705 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Scotland
  • Local time:12:09 AM

Posted 17 December 2014 - 01:30 PM

When you search the internet for instructions on how to edit any particular file, you will often find that the command utilises a text editor that you don't already have. There are many text editors available for Linux, and nano is a simple command line editor that comes installed on most major Linux distros.

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:

snapshotKubuntu18_zps90b3ea0b.jpeg

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.conf
To 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
snapshotKubuntu19_zps7f003a3e.jpeg

After entering my password and pressing Return, the file opens in nano:

snapshotKubuntu21_zps49e5d22f.jpeg

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.

snapshotKubuntu22_zps2901726b.jpeg

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.

snapshotKubuntu25_zps3743f65f.jpeg

Type y for yes, then:

snapshotKubuntu26_zpsb18c7e1a.jpeg

..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:

snapshotKubuntu27_zps345f6690.jpeg

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.


BC AdBot (Login to Remove)

 


m

#2 bmike1

bmike1

  • Members
  • 596 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Gainesville, Florida, USA
  • Local time:07:09 PM

Posted 17 December 2014 - 03:59 PM

Good how-to Al. However, you forgot to mention running 'sudo updatedb' before you run locate. Info for those who don't know: That command scans for any new additions or subtractions to your system for the locate database.
Say you have added a file to your system. Until you run 'updatedb' the program 'locate' won't know anything about it. The first time you run updatedb might take a while.

Edited by bmike1, 17 December 2014 - 04:10 PM.

A/V Software? I don't need A/V software. I've run Linux since '98 w/o A/V software and have never had a virus. I never even had a firewall until '01 when I began to get routers with firewalls pre installed. With Linux if a vulnerability is detected a fix is quickly found and then upon your next update the vulnerability is patched.  If you must worry about viruses  on a Linux system only worry about them in the sense that you can infect a windows user. I recommend Linux Mint or, if you need a lighter weight operating system that fits on a cd, MX14 or AntiX.


#3 Al1000

Al1000
  • Topic Starter

  • Global Moderator
  • 6,705 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Scotland
  • Local time:12:09 AM

Posted 17 December 2014 - 06:51 PM

Thanks Mike! I'll edit my OP to include a reference to your post.

#4 bmike1

bmike1

  • Members
  • 596 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Gainesville, Florida, USA
  • Local time:07:09 PM

Posted 18 December 2014 - 01:45 AM

if you can still edit it I'd put it into your post.


A/V Software? I don't need A/V software. I've run Linux since '98 w/o A/V software and have never had a virus. I never even had a firewall until '01 when I began to get routers with firewalls pre installed. With Linux if a vulnerability is detected a fix is quickly found and then upon your next update the vulnerability is patched.  If you must worry about viruses  on a Linux system only worry about them in the sense that you can infect a windows user. I recommend Linux Mint or, if you need a lighter weight operating system that fits on a cd, MX14 or AntiX.


#5 bmike1

bmike1

  • Members
  • 596 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Gainesville, Florida, USA
  • Local time:07:09 PM

Posted 19 December 2014 - 12:10 AM

I think a moderator needs to put this in the how-to pined topic.


A/V Software? I don't need A/V software. I've run Linux since '98 w/o A/V software and have never had a virus. I never even had a firewall until '01 when I began to get routers with firewalls pre installed. With Linux if a vulnerability is detected a fix is quickly found and then upon your next update the vulnerability is patched.  If you must worry about viruses  on a Linux system only worry about them in the sense that you can infect a windows user. I recommend Linux Mint or, if you need a lighter weight operating system that fits on a cd, MX14 or AntiX.


#6 Guest_hollowface_*

Guest_hollowface_*

  • Guests
  • OFFLINE
  •  

Posted 19 December 2014 - 02:21 AM

Great tutorial, thanks for sharing.

 

Related information:

 

If you plan to edit lots of files, and don't wish to have to type sudo each time you can use "sudo -i" which will simulate a login as root. Meaning type "sudo -i", enter your password, then type "nano /folder/file.file", from this point on you don't need to type "sudo -i" anymore, just "nano /folder/file.file". When finished type "exit" to return to your user session.

 

If anyone is using a distro that doesn't have Sudo, use "su root" instead, enter your root user's password, and then type the command "nano /folder/file.file". Type "su username" to return to your previously logged in user (substitue "username" for your user's name) or just type "exit".

 

For editing OS/program related stuff you'll probably editing stuff owned by root, or maybe your user. However for other files clunking around on your drive you can use "ls -l /folder/file.file" to determine who owns a file (the order is owner, and group), then "su username" to login as that user, enter the user's password, and then type "nano /folder/file.file". Type "su username" to return to your previously logged in user (substitue "username" for your user's name) or just type "exit".






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users