I am completely confused between umask and chmod. Both are used to give permissions to the files. But where exactly is the difference and when to use them.
I have read the online documentation but both are looking same to me.
umask: umask is used to set default file permissions. These permissions will be used to all subsequent files during their creation. chmod : used to change file and directory permissions.
As per my understanding if for example file test.doc is created.
By default unix gives the file 022 umask code.
Now when I change it to chmod 666 test.doc I can change the permission level of this file.
Now what if i use umask 666 for the same file.
What difference it happens when I use chmod 666 and umask 666
umask
sets an environment variable which automatically sets file permissions for newly created files.chmod
changes the permissions of existing files.umask
does not set "an environment variable" What it does do is set the file mode creation mask of the current shell execution environment.