Organize your linux--umask every day | chmod

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.