Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does :w! work but not :wq? File is read only error

Tags:

vi

Why does :wq fail with File is read only, but :w! then :q succeeds?

This file was opened by the command sudo vi filename since the permissions are 550

like image 755
wizurd Avatar asked Dec 07 '25 01:12

wizurd


1 Answers

The sudo command allows you to override the permissions of the file 550 (rxrx-). :wq won't override but :w! will.

Note that the purpose of the ! is to 'force' your command w. :wq doesn't include the 'force' modifier.

like image 101
KevinDTimm Avatar answered Dec 10 '25 10:12

KevinDTimm