-2

I am trying to edit a file in vi editor - and when I try to save the changes it says READ ONLY. Even when I try to do a chmod I get an error saying I cannot do so.

I have logged in Unix using a personal ID and not a service one

Nidhin_toms
  • 707
  • 4
  • 18
  • 29
  • You should ask your admin for the root password. Then you're 31337 and can chmod 777 EVERYTHING, thus solving the problem forevermore. – Jeff Watkins Mar 12 '15 at 13:22
  • Thanks Jeff for the answer - not sure why my post is downvoted by others cos I have a question and am not an expert in Unix – Nidhin_toms Mar 12 '15 at 13:24
  • Good grief... do not follow my advice, that was perhaps a poorly judged joke. You should try sudo if you have the correct substitute users in your settings. If not, you may have to contact an admin – Jeff Watkins Mar 12 '15 at 13:27
  • Anyways I learnt something new - sudo – Nidhin_toms Mar 12 '15 at 13:28
  • Although if your admin is gullible enough to give you root... The world is your oyster. – Jeff Watkins Mar 12 '15 at 13:29
  • @Nidhin_toms: While I wouldn't down-vote your answer (and haven't), I would tell you that your question is not _programmming_-related and thus belongs on a different StackExchange site, such as http://unix.stackexchange.com. – mklement0 Mar 12 '15 at 13:44

2 Answers2

2

Try opening editing the file in vim using: sudo vim <filename>

Some people also recommend adding this to your .vimrc file so you can open the file without sudo then write to it anyway using :w!!

" Sudo to write
cnoremap w!! w !sudo tee % >/dev/null
Nathan
  • 7,627
  • 11
  • 46
  • 80
  • 1
    What is the difference between vim and vi – Nidhin_toms Mar 12 '15 at 13:23
  • 2
    Vim is the "improved" Vi. In practical terms they're the same. In either case, just use `sudo` in front of vim or vi to open the file. – Nathan Mar 12 '15 at 13:25
  • One caveat: Some platforms - e.g., Ubuntu - have only a `vi`, not a `vim` executable _in the path_ (even though `vi` may be a _symlink to_ `vim`). – mklement0 Mar 12 '15 at 13:53
2

Because you aren't owner of this file. You need to sudo vim with an owner user.

Turrican
  • 607
  • 4
  • 9
  • I could su to my service ID and I could execute the file with no problem - how do I do the same with my personal ID ? – Nidhin_toms Mar 12 '15 at 13:22