linux umask_Linux umask命令教程,包括示例,数字和符号表示

linux umask

linux umask

umask command is used to set default file and folder permission in  Linux operating system. File and folder permissions are important because the permission enables or deny different users, groups and others to access, read, write and execute of the given file. In this tutorial, we will learn how to use umask command to set default read, write and execute permissions.

umask命令用于在Linux操作系统中设置默认文件和文件夹权限。 文件和文件夹权限很重要,因为该权限允许或拒绝不同的用户,组和其他用户访问,读取,写入和执行给定文件。 在本教程中,我们将学习如何使用umask命令设置默认的读取,写入和执行权限。

句法 (Syntax)

The syntax of the umask command is very simple where we just provide the permissions.

umask命令的语法非常简单,我们只提供权限。

umask PERMISSIONS

权限 (Permissions)

Linux is a file-based operating system where there are 3 permissions.

Linux是具有3个权限的基于文件的操作系统。

  • `r` means read where reading given file or folder is specified

    r表示在指定读取给定文件或文件夹的地方进行读取
  • `x` means execute where execution of the given file specified. As folders can not be executed we can not use this permission for folders or directories.

    x表示在指定执行给定文件的地方执行。 由于无法执行文件夹,因此我们无法对文件夹或目录使用此权限。
  • `w` means write where writing or appending to the specified file or folder.

    w表示在写入或附加到指定文件或文件夹的位置写入。

The permissions has also numeric representation like below.

权限也具有数字表示形式,如下所示。

numberpermission
4read
2write
1execute
允许
4
2
1个执行

If we want to specify multiple permission we need to sum up their numeric representation and line symbolic representation like below.

如果要指定多个权限,则需要对它们的数字表示和线符号表示进行汇总,如下所示。

read value +write value +execute value =numeric

value:

symbolic equivalent:
11x
22w
213wx
44r
415rx
426rw
4217rwx
读取值+ 写值+ 执行值= 数字

值:

等价的符号:
1个 1个X
2 2 w
2 1个 3 wx
4 4 [R
4 1个 5 接收
4 2 6 w
4 2 1个 7 w

For example, If we want o make given file read and executable bu not writeable we can use numeric 5 or symbolic rx.

例如,如果要使给定文件可读且可执行文件bu不可写,则可以使用数字5或符号rx。

用户数 (Users)

Linux operating systems use 3 category user types like owner, group and others

Linux操作系统使用3类用户类型,例如所有者,组和其他

  • `owner` is the user who owns the file completely. This user generally has all rights like read, write and execute. But in some cases to prevent accidents some permissions can be changed or removed.

    “所有者”是完全拥有文件的用户。 该用户通常拥有所有权限,例如读取,写入和执行。 但是在某些情况下,为防止发生意外,可以更改或删除某些权限。
  • `group` is the group owns the given file or directory. For example, `sudoer` group owns some administrative files where they can use them according to their permissions.

    “ group”是拥有给定文件或目录的组。 例如,“ sudoer”组拥有一些管理文件,他们可以根据其权限使用它们。
  • `other` means all other users except owner and group. This can be useful for entities that do not have any relationship with the given file. Generally, we can make a file do not have any read, write or execute permission to a file for other users. But in some cases, we may provide the read permission.

    “其他”是指除所有者和组之外的所有其他用户。 这对于与给定文件没有任何关系的实体很有用。 通常,我们可以使文件没有其他用户对文件的任何读,写或执行权限。 但是在某些情况下,我们可能会提供读取权限。

权限值 (Permission Values)

We have learned the default user and permission usage for Linux operating systems. umask command uses these users and permission a bit different. Actually, permission values are working a bit different. We do a bitwise operation on the permission values in order to use with umask. For example, in order to set 775 for default permission, we need to provide 002 to the umask command. This can create some problems and errors during umask command usage but we can check with the -S option the regular permission values of the current files and folders.

我们已经了解了Linux操作系统的默认用户和权限用法。 umask命令使用的这些用户和权限有些不同。 实际上,权限值的作用有些不同。 我们对权限值进行按位运算,以便与umask一起使用。 例如,为了将775设置为默认权限,我们需要为umask命令提供002。 这可能会在使用umask命令期间造成一些问题和错误,但是我们可以使用-S选项检查当前文件和文件夹的常规权限值。

$ umask

$ umask -S
Permission Values
Permission Values
权限值

We can see that 0022 is equal to user rwx, group rx and others rx.

我们可以看到0022等于用户rwx,组rx和其他rx。

umask权限数字演示 (umask Permission Digit Presentation)

We can use the following table to set umask permission digit presentation.

我们可以使用下表来设置umask权限数字的表示形式。

umask digitdefault file permissionsdefault directory permissions
rwrwx
1rwrw
2rrx
3rr
4wwx
5ww
6xx
7(no permission allowed)(no permission allowed)
umask数字 默认文件权限默认目录权限
w w
1个 w w
2 [R 接收
3 [R [R
4 w wx
5 w w
6 X X
7 (未经允许) (未经允许)

以数字格式打印当前权限 (Print Current Permission In Numerical Format)

We can print currently active umask permissions which will show file and folder default permissions like below.

我们可以打印当前活动的umask权限,该权限将显示文件和文件夹的默认权限,如下所示。

$ umask
Print Current Permission In Numerical Format
Print Current Permission In Numerical Format
以数字格式打印当前权限

以符号格式打印当前权限(Print Current Permission In Symbol Format)

We can use -S option with the umask command in order to list the current file and folder permissions.

我们可以在umask命令中使用-S选项,以列出当前文件和文件夹的权限。

$ umask -S
Print Current Permission In Symbol Format
Print Current Permission In Symbol Format
以符号格式打印当前权限

设定权限(Set Permission)

Now we will set the file and folder default permissions with the umask command. As learned previously we will use umask type permissions. In this example, we will set the permission user read+write+execute , group read+execute and others none.

现在,我们将使用umask命令设置文件和文件夹的默认权限。 如前所述,我们将使用umask类型权限。 在此示例中,我们将权限用户设置为read + write + execute,组read + execute,其他用户均未设置。

$ umask 027
Set Permission
Set Permission
设定权限

Another way is using following command syntax

另一种方法是使用以下命令语法

$ umask u=rwx,g=rx,o=

删除权限 (Delete Permission)

We can also delete or remove currently existing permissions to the owner, group or others. We will use - and provide the user and permission. In this example, we will remove group execution permission. g is used for the group and x is used for executing.

我们还可以删除或删除所有者,组或其他人当前拥有的权限。 我们将使用-并提供用户和许可。 在此示例中,我们将删除组执行权限。 g用于组, x用于执行。

$ umask g-x

PHP umask函数 (PHP umask Function)

PHP is a Linux based programming language where is provides native Linux functions. PHP provides umask function which can be used to list and set default file and folder permissions.

PHP是一种基于Linux的编程语言,其中提供了本机Linux功能。 PHP提供了umask功能,可用于列出和设置默认文件和文件夹权限。

In this example, we will set the current file and folder permission with the 0077 permission.

在此示例中,我们将使用0077权限设置当前文件和文件夹权限。

<?php

umask(0077);

?>

We can also print current file and folder permissions without providing any parameter to the PHP umask() function like below.

我们还可以打印当前文件和文件夹权限,而无需为PHP umask()函数提供任何参数,如下所示。

<?php

umask();

?>
LEARN MORE  How To Disable SELinux Temporarily or Permanently in CentOS, RHEL, Fedora
了解更多如何在CentOS,RHEL,Fedora中临时或永久禁用SELinux

翻译自: https://www.poftut.com/linux-umask-command-tutorial-with-examples-numeric-and-symbolic-representations/

linux umask

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值