In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "what is the use principle and calculation method of umask command under linux". In daily operation, I believe that many people have doubts about the use principle and calculation method of umask command under linux. Xiaobian consulted all kinds of data and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "what is the use principle and calculation method of umask command under linux". Next, please follow the editor to study!
Use of umask umask
Umask gives default permissions to new files and directories.
You can see that the directory created by root is 755 and the file is 644
[root@zaishu zaishu] # touch test.txt [root@zaishu zaishu] # mkdir test [root@zaishu zaishu] # ls-ltotal 0drwxr-xr-x 2 root root 6 Nov 25 16:29 test-rw-r--r-- 1 root root 0 Nov 25 16:28 test.txt
Ordinary user
You can see that the directory created by the average user is 775 and the file is 664
[mysql@zaishu ~] $touch test.txt [mysql@zaishu ~] $mkdir test [mysql@zaishu ~] $ls-ltotal 0drwxrwxr-x 2 mysql mysql 6 Nov 25 16:30 test-rw-rw-r-- 1 mysql mysql 0 Nov 25 16:30 test.txt
These default permission values are obtained through the umask setting operation.
Principle
Linux gives initial permissions to all newly created files and directories by using the default permissions of umask. So how do we know the value of the default permission for umask? You can use the umask command directly:
1. Umask value [root@zaishu ~] # umask0022 [mysql@zaishu ~] $umask0002
# the default is 0022 for root users and 0002 for ordinary users
The umask default permission does consist of four octal numbers, and the first number represents the special permissions (SetUID, SetGID, Sticky BIT) that the file has first ignored. The last three bits "022" correspond to-wmurw -.
two。 Maximum file directory permissions
On Linux systems, the maximum default permissions for files and directories are not the same:
As far as files are concerned, the maximum default permission you can have is 666, that is, rw-rw-rw-. X is the maximum permission for a file, which is not given when creating a new file, but can only be given manually by the user.
As far as directories are concerned, the maximum default permission you have is 777, or rwxrwxrwx.
3. Conventional calculation
The initial permissions of files and directories are calculated to:
Initial permissions for files (or directories) = maximum default permissions for files (or directories)-umask permissions
[mysql@zaishu ~] $umask0002 [mysql@zaishu ~] $mkdir test [mysql@zaishu ~] $ll-d testdrwxrwxr-x 2 mysql mysql 6 Nov 26 10:50 test / / directory can have a maximum default permission of 777 777-002 = 775 [mysql@zaishu ~] $touch h.txt [mysql@zaishu ~] $ll h.txt-rw-rw-r-- 1 mysql mysql 0 Nov 26 10:52 h.txt / / File maximum permissions 666,666-002 (ordinary users) 666,002 (ordinary users) # touch h3 [root@zaishu ~] # ls-l-rw-r--r-- 1 root root 0 Nov 26 10:53 h3 / File maximum permissions 666,666-002 (root) 666-022 = 6444. Rigorous calculation
When calculating the initial permissions of a file or directory, it is not rigorous to subtract directly from the digital form of the maximum default permissions and umask permissions. For example, if the default permission value of umask is 033, the initial permission of the file is calculated in numeric form, 666-033 permissions 633, but we get (rw-rw-rw-)-(- wx-wx) = (rw-r-r--) in alphabetical form, which translates to 644 in numerical form.
The subtraction here actually means "masking", that is, the public part of the maximum default permission and umask permission will be covered by subtraction, and the final remaining "maximum default permission" is the initial permission given to the file or directory.
The umask value is modified by 1. Temporarily effective (current session)
The umask permission value can be modified directly:
[root@localhost ~] # umask 002 [root@localhost ~] # umask0002 [root@localhost ~] # umask 033 [root@localhost ~] # umask0033
The modified umask in this way is only temporarily valid and will fail once you restart or log in to the system.
two。 Take effect permanently
For the changes to take effect permanently, you need to modify the corresponding environment variable configuration file / etc/profile.
[root@zaishu~] # vim / etc/profile... Omit part of the content. If [$UID-gt 199] & & ["'id-gn'" = "'id-un'"] Then umask 002 # if UID is greater than 1999 (ordinary user), then use this umask value else umask 022 # if UID is less than 1999( super user), then use this umask value fi, and the study on "what is the principle and calculation method of umask command under linux" is over. I hope to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.