Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change file permission from within vi

Tags:

vim

vi

I sometimes open a read-only file in vi, forgetting to do chmod +w before opening it. Is there way to change the file from within vi?

Something like !r chmod +w [filename]?

Is there a shortcut to refer to the currently open file without spelling it's long name?

like image 405
vehomzzz Avatar asked Oct 22 '09 11:10

vehomzzz


People also ask

How do I change permissions in vi?

Example: :echo getfperm("/etc/passwd") This will hopefully (from a security point of view) display the string "rw-r--r--" or even "rw-------". This adds read, write and execute permissions to the "foo. txt" file in the current directory.

How do I change a read only file in vi?

Just use vi's exclamation mark suffix to the write command (:w!) to force overwriting your own READONLY file.

How do I give permission to 644?

Change directory with cd command to the desired location under with you need to all directories to 755, and all files to 644 permissions. Then use first command to chmod 755 for all directories and sub directories. The second command will change all the files permission to 0644 (chmod 644) under the directory tree.


1 Answers

Just use

:!chmod +w % 

in command mode. % will be replaced by the current file name.

like image 166
David Larochette Avatar answered Sep 19 '22 11:09

David Larochette