Write permission of a file in unix

1k views Asked by At

While assigning permissions to a file with the command:

$ chmod +rwx file1.txt

Why is it that read and execute permissions are assigned to everybody, but write permission is only assigned to the user?

2

There are 2 answers

0
Shailesh On

yes it depends on the umask of your system u might be having 0022 as your umask

chmord +rwx file.txt ---- 777

the resulting permission 777-022=755

2
GIZ On

chmod(1)
A combination of the letters ugoa controls which users' access to the file will be changed: the user who owns it (u), other users in the file's group (g), other users not in the file's group (o), or all users (a). If none of these are given, the effect is as if (a) were given, but bits that are set in the umask are not affected.

This is pretty clear. You have to check your umask value:

$ umask 
0002
$ touch xyz
$ ls -l xyz
-rw-rw-r-- 1 user user 0 Sep  6 22:56 xyz
$ chmod +rwx xyz
$ ls -l xyz
-rwxrwxr-x 1 user user 0 Sep  6 22:56 xyz

$ chmod a+rwx xyz
$ ls -l xyz
-rwxrwxrwx 1 user user 0 Sep  6 22:56 xyz

Have a look at this page: Default File Permissions: umask