How do I give write permission to file in Linux?

boom :

How can I (programmatically) give write permission on a file to a particular user in Linux? Like, for example, its owner? Everyone has read access to this file.

DarkDust :

In a shell or shell script simply use:

chmod u+w <filename>

This only modifies the write bit for the user, all other flags remain untouched.

If you want to do it in a C program, you need to use:

int chmod(const char *path, mode_t mode);

First query the existing mode via

int stat(const char *path, struct stat *buf);

... and just set the write bit by doing newMode = oldMode | S_IWUSR. See man 2 chmod and man 2 stat for details.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related