Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the umask command in Linux

2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly shows you "how to use the umask command in Linux". The content is simple and clear. I hope it can help you solve your doubts. Let the editor lead you to study and learn how to use the umask command in Linux.

The Linux common command umask command specifies the preset permission mask when creating the file, and umask can be used to set the [permission mask]. The permission mask consists of three octal digits. After the existing access permissions are subtracted from the permission mask, the default permissions when the file is created can be generated.

Umask displays or sets the permission mask for creating files.

Summary umask [- p] [- S] [mode] the main purpose is to display the current file permission mask.

Sets the permission mask for creating files in octal numbers.

Sets the permission mask for creating files by combining symbols.

Parameter mode (optional): octal number or symbol combination.

Option-p: specify this option when there are no parameters, and the resulting output format can be reused as input;-S: output the permission mask to create the file in a symbolic combination, and in octal when not using this option. The return status of the return value is successful unless an illegal option or parameter is given.

The following examples all assume that the file permission mask is 0022.

# outputs the permission mask to create the file in octal number. Umask-p # execution result: umask 0022 # outputs the permission mask to create the file in the way of symbol combination. Umask-S # implementation result: the DESCRIPTION paragraph of the man chmod document refers to the DESCRIPTION paragraph of the man chmod document:

The u symbol represents the current user.

The g symbol represents a user who is in the same group as the current user, hereinafter referred to as the group user.

The o symbol represents other users.

The a symbol represents all users.

The r symbol represents read permissions and the octal number 4.

The w symbol represents write permissions and the octal number 2.

The x symbol represents the execution permission and the octal number 1.

The + symbol means to add the appropriate permissions for the target user.

-the symbol represents the deletion of the corresponding permissions of the target user.

The = symbol means to add the appropriate permissions for the target user and remove the permissions that are not mentioned.

So the result just output in symbolic form is equal to 0755.

To set the same permissions with octal numbers, umask requires an additional subtraction of 0777-0755, or 0022, while chmod does not.

Add, delete and assign permissions for symbol combination mode.

# add permissions: # add write permissions for group users. Umask Grouw # Delete permissions: # Delete other users' write and execute permissions umask o-wx # assignment permissions: # assign all user permissions, which is equivalent to umask upright rwx journal glossrwx journal obliterrwx umask a=rwx # to remove the read, write and execute permissions of other users. Umask o = create folders, files (assuming the current directory does not exist)

# create a file touch test.sh # View permissions and find that the settings of execution permissions do not work. Stat test.sh # create a folder touch newdir # View permissions and find that the settings of execution permissions can work. Stat newdir note that this command is a bash built-in command. For related help, please see the help command.

Chmod is used to change the permissions of existing objects, and umask affects the permissions of new objects later.

Please use this command carefully, especially do not revoke the current user's read rights, which will cause you to use the TAB key on the terminal to make up for the Times error.

The above is all the contents of the article "how to use umask commands in Linux". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report