Linux mkdir function mode permission setting method

  
                  Mkdir function prototype (includes #include <sys/stat.h>): int mkdir(const char *path, mode_t mode); parameter: path—— directory name, such as abc, /var/www/Abc and other mode—— directory permission return value: return 0 for success, return -1 for error, and set errno value. For the definition of Mode, please refer to: http://pubs.opengroup.org/onlinepubs/7908799/xsh/sysstat.h.html Of course, you can also use macro parameters similar to S_IRWXU, S_IRUSR..., after all, it is difficult to remember It is not as good as the 0421 in octal. The combination style is: owner-group-others, different people are divided into three rules read-write-execute (rwx), all licenses are 7.1, using mkdir ("test", 777) when programming, give an error: mkdir ("test",0777); written as mkdir("test",777) may not be executed. But vaguely remember, there used to be no mistakes in the previous use of 777, specifically forgot, anyway, it is absolutely correct to write according to the norm. 2, umask command use another assumption that your program directory is under /root/abc/, then if your program wants to create a directory under /var/www when executing, it is possible that you always create a directory of 0777 is always created 0755 directory, you can try the umask (0) command. Umask is only valid for the current directory. The default umask value is 0022, so you cannot create a directory of 0777 directly in another place. Instead, 0777-0022=07553, how to create a user group folder /etc/passwd and /etc/group to find UID and gidmkdir /var/ugroup we can use chown directly to change the file owner. Chown root:newuser /var/ugroup modify the permissions chmod 740 /var/ugroup/*4, view the permissions of the directory after the creation of the command: locate the user group directory, execute: ls -all will display something like: drwxrwxr-x Results (0775).
Copyright © Windows knowledge All Rights Reserved