Cygwin - how to edit a read only file?

4

1

I'm trying to edit /etc/hosts using Vi in Cygwin but it's read only. Is there a command similar to sudo? How do I edit a read-only file?

Thanks

Nope

Posted 2011-03-20T17:43:24.120

Reputation: 143

Answers

2

Try doing a forced overwrite. Instead of :wq to write and quit, try: :wq! to force write and quit.

Majenko

Posted 2011-03-20T17:43:24.120

Reputation: 29 007

1@Nope You should accept the newer answer posted by Philipp if you ever sign on again! – Matthew – 2014-09-30T21:06:19.050

Didn't work.... – Nope – 2011-03-20T17:57:52.657

3Try using the Windows runas command then? runas /user:Administrator vi /etc/hosts – Majenko – 2011-03-20T17:59:21.020

3Running cygwin as administrator allowed me to edit the file. Thanks for your help – Nope – 2011-03-20T18:05:45.160

7

Opening your cygwin shell as Administrator will grant your user root access. Then the files will no longer be readonly.

Philipp Claßen

Posted 2011-03-20T17:43:24.120

Reputation: 360