When we log into the system and create a file that always has a default permission, how does this permission come from? That's what Umask did. Umask set the user to create the default permissions of the file, it is the opposite of chmod effect, Umask set the right "complement", and chmod set the file permission code. You can generally set $[HOME]/.BASHRC values in/etc/profile,/ETC/BASHRC, $ [Home]/.bash_profile, $[home]/.profile, or umask. Depending on the Linux distribution, such as Fedora19 to change its umask value, the value added umask under $[home]/.profile or $[home]/.bash_profile cannot overwrite the configuration value in/etc/profile , you must increase the Umask value under $[HOME]/.BASHRC to permanently define your own umask value.
#include"apue.h"#include<stdio.h>#include<unistd.h>#include<fcntl.h>#include<sys/stat.h>#include<stdlib.h>#defineRWRWRW (S_irusr | S_IWUSR | S_irgrp | S_iwgrp | S_iroth | S_iwoth)intMain () {structstat statbuf; //changing the umask value of a process does not change the umask of its parent processUmask0); if(Creat ("Foo", RWRWRW) <0) {printf ("Create Error"); Exit (0); } umask (S_irgrp| S_iwgrp | S_iroth |S_iwoth); if(Creat ("Bar", RWRWRW) <0) {printf ("Create Error"); Exit (0); } /*chmod changing file access rights*/ /*if (stat ("foo", &statbuf) <0) {printf ("stat error"); Exit (0); }//S_IXGRP set the group ID bit at execution time set the group ID bits off the group execution bit if (chmod ("foo", (Statbuf.st_mode & ~S_IXGRP) | S_isgid) < 0) {printf ("chmod foo error"); Exit (0); } if (chmod ("Bar", S_IRUSR | S_IWUSR | S_irgrp | S_iroth)) {printf ("chmod bar Error"); Exit (0); } */ return 0;}
Organize your linux--umask every day | chmod