Home » questions » How do you edit a read-only file in Vi ?

How do you edit a read-only file in Vi ?

2006-08-07 09:31:52, Category: Programming & Design
My references only say that I should save it using :w! but I keep getting the message "Cant open file for writing". Its a permissions issue but I am able to open the file and read it.

Answers

  1. str0ngsad

    On 2006-08-07 09:38:27


    Try changing the permissions of the file. If you do not own the file, do a chown to make you the owner (have to be root to do this) Or the file could just be a read only file so you have to chmod it to a level that can be modified. Always make a backup of the file before you try to edit it.
  2. Bryan A

    On 2006-08-07 09:37:02


    You probably don't have the right permissions to overwrite the file. You may need to be root to overwrite the file. Try saving the file somewhere else, by doing: :w ~/filename.txt and then become root or use sudo to copy the new file over the old file.
  3. mike_w40

    On 2006-08-07 09:35:38


    It's not a vi issue, it'll be a permissions issue. Make sure you have write permissions on the file before editing it. For example, if you're a normal user editing something in /etc/, you shouldn't be able to save that file. For that, you'd need to be root.
  4. John J

    On 2006-08-07 09:55:07


    its a permissions issue. If you can't open the file you don't even have read access for it. You should be able to run "ls -la filename" which will list the file as well as a lot of other data. At the beginning of the line will be something like "-rw-r----- {owner} {group}..." the way this is set up is: - -> type of file, usually you will see a d for directory, there are a number of other types rw- -> owner permissions r for read w for write - for not executable (could also be x) ditto on the next two sets of three (r-- for read only group and --- for no permissions global) If you aren't the owner and aren't in the same group (run "whoami" to find your group) you have the global permissions. if you can read it, either copy it to your home directory, or a directory where you have permissions to write, and edit it there or while editing type ":w ~/filename"
  5. moviedhamaka

    On 2006-08-07 09:36:52


    The file may be open by another process and my not allow writing. You can do the following Make a copy of the original and edit the copy. Identify and close the program that hold the original file and copy over the new file to old one