Editing a read-only file in Linux

I have had another question:

Trying to get my wireless dongle working. I’ve found a file it says I have to edit, but the file is read-only, and I can’t change the status in Properties. I’m starting to dislike Linux already 🙁

Editing a read-only file in Linux is easy when you know how. Before you do anything else you copy the original file and paste it somewhere safe, like on your desktop, so if anything goes wrong you can restore it.

Editing the file:
As you are wanting to end up with a file containing an altered load of code there are two ways of doing it:

  1. The first way is to get superuser permissions to alter the original, then save the changes.
  2. The second is the longer way. Good if you are nervous about getting something wrong.

The first way
Open a terminal (should be in your list of programmes, will look like old fashioned computer display with a command prompt). The next thing is to open the read-only file from a command in the terminal.

Paste in terminal: gksu gedit /usr/local/share/applications/defaults.list [or your file location]

You can get the location by right-clicking on the file and selecting ‘copy’ then paste it in the terminal. Use right-click ‘paste’ as short-cuts won’t work.
gksu is the super user command, could have used sudo.
gedit is the editor for the document, if your machine uses a different editor put the name of it there instead of gedit.
/usr/local/share/applications/defaults.list is just an example, you put the location of your file there.

You alter the file as you want using gedit. Then save it, while you have superuser or ‘root’ authority over it.

Second way
Open the read-only file and paste the contents into a blank gedit. Or open the read-only file and save it to your desktop. Close the read-only one and open the one on your desktop. You will have permissions to alter it. Change what you want then save changes.

Next you want to replace the old one with your altered one.

Paste in terminal after the command prompt:  gksu nautilus /usr/local/share/applications/ [or the folder where your file is]

That command would open the file browser but with superuser authority. It will take you to the folder containing your old file. You drag your new file there to replace the old one. Must have the same name as the old one.

If you are not using Ubuntu the file browser may be a different one, but Nautilus is common to many different flavours of Linux. If yours is different put in the name of your file browser.

For someone new to Linux I have good news. A good way to find answers to you Linux questions is to google your question mentioning your version of Linux. As Linux is open source you find all sorts of help out there. People like me stick the answers in websites and blogs.

8 thoughts on “Editing a read-only file in Linux

  1. I’m trying really hard to be patient, but it looks like Linux isn’t going to win me over. Everything is so complicated (GUIs have been around since the 1980s, so why do so many things require the Terminal?). I’ve spent hours already trying to work out how to do things. This afternoon I must have spent at least an hour trying to work out how to increase the brightness of my screen (it’s really dark when in Linux), but I’ve not managed to work out the solution. I also wanted to access my shared files on my Windows computer, but got nowhere. I did eventually find a page that has everything in plain English (http://pcworld.about.net/magazine/2312p180id122932.htm), but the instructions are for Suse, and I have Ubuntu, which is presumably why I can’t find KDE or “Network Browsing” or “Konqueror”.

  2. I just want to say thanks! I’ve been spending so much time trying to edit one document, and your post worked as a charm. I love it!

Leave a Reply

Your email address will not be published. Required fields are marked *