Ubuntu: How can I edit a readonly file? [closed]



Question:

We have no privileges to change file permissions. We have no permissions even for super users. How can we edit this file?


Solution:1

As pointed out by dsstorefile, you can copy the contents of the file to another file for which you have writing rights, and then edit the writable file.

Then you can put the edited file back in place by deleting the original file and copying your new file at the same place.

In more detail:

Using command-line / terminal

If you can create files in the directory where your file is

If the original read-only file is called original.csv and you want your writable file to be called data.csv, you can open a terminal, go to the directory where your file is, and run the command:

cat original.csv > data.csv  

and now you can open and edit the data.csv file.

Once the editing is done,

rm original.csv  

When asked if you want to delete the read-only file, answer y

mv data.csv original.csv  

If your file is in a directory you cannot write to

If /path/to/writable/dir/ is the name of a directory you can write to, if the original read-only file is called original.csv and if you want your writable file to be called data.csv, you can open a terminal, go to the directory where your file is, and run the command:

cat original.csv > /path/to/writable/dir/data.csv  

and now you can open and edit the data.csv file in /path/to/writable/dir/. In this situation, you won't be able to put your modified file where the original file was.

Without using terminal

  • Open your csv with a text editor, for example gedit .
  • Copy all the content of the file, for example with Ctrl+A Ctrl+C
  • Create a new file within the editor
  • Paste the contents of the csv, for example with Ctrl+V
  • Save your new file with a name that ends with .csv
  • delete the original file
  • move the edited file where the original file was, and rename it if necessary

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »