Glam Prestige Journal

Bright entertainment trends with youth appeal.

I created a file using

sudo vim filename

but I can't modify it after creating.

How can I make it possible to modify this file?

2

1 Answer

By executing this command

sudo vim filename

you create new file, whose owner is the root user. You can confirm that by executing ls -al. From the output you can see that the owner and the group to which the file belongs are set to root.

If you try to edit it with your normal user, you wont be able, because the file does not belongs to your user. Again you are able to read the file but not write to it, because of the permissions. You can check them to from the command line with ls -al command. It should be something like:

-rw-r--r-- 1 root root 4 Apr 9 07:40 filename

the first part -rw-r--r-- means that only owner can read and write to file, users from the same group and other user can only read the file.

Here is a good diagram that describes the meaning of permissions:

Permissions

If you wish to be able to edit the file, you must do so as the root user - this is almost always the best way:

sudo vim filename

If you wish to edit it as normal user you can assign additional permissions to it, (but you should not do this to system files outside your home directory - use sudo to edit them instead):

sudo chmod 777 filename

This way the file will be readable, writable and executable from every user. This is rarely a good idea.

To give ONLY write permissions to all other users:

sudo chmod o+w filename

Otherwise if you want the file to be writable only by you, you can change the owner to you:

sudo chown yourusername:root filename

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy