权限管理命令--chmod

权限管理命令--chmod

说明:示例中以"#","~"开头的表示输入

权限管理命令--chmod

  • 功能描述:改变文件或者目录权限
  • 执行权限:所有用户
  • 所在路径:/bin/chmod

示例1

# ls -l chmod.txt 
-rw-r--r-- 1 root root 10 9月  16 20:52 chmod.txt
# chmod u+x chmod.txt 
# ls -l chmod.txt 
-rwxr--r-- 1 root root 10 9月  16 20:52 chmod.txt

如上,chmod u+x chmod.txt 表示给所有者(u)添加执行(+x)权限.

示例2

# ls -l chmod.txt 
-rwxr--r-- 1 root root 10 9月  16 20:52 chmod.txt
# chmod u-x chmod.txt 
# ls -l chmod.txt 
-rw-r--r-- 1 root root 10 9月  16 20:52 chmod.txt

如上,chmod u-x chmod.txt 表示给所有者(u)减去执行(-x)权限.

示例3

# ls -l chmod.txt 
-rw-r--r-- 1 root root 10 9月  16 20:52 chmod.txt
# chmod g+x chmod.txt 
# ls -l chmod.txt 
-rw-r-xr-- 1 root root 10 9月  16 20:52 chmod.txt

如上,chmod g+x chmod.txt 表示给所属组(g)添加执行(+x)权限.

示例4

# ls -l chmod.txt 
-rw-r-xr-- 1 root root 10 9月  16 20:52 chmod.txt
# chmod o+x chmod.txt 
# ls -l chmod.txt 
-rw-r-xr-x 1 root root 10 9月  16 20:52 chmod.txt

如上,chmod o+x chmod.txt 表示给其他人(o)添加执行(+x)权限.

示例5

# ls -l chmod.txt 
-rw-r-xr-x 1 root root 10 9月  16 20:52 chmod.txt
# chmod u+x,o-x chmod.txt 
# ls -l chmod.txt 
-rwxr-xr-- 1 root root 10 9月  16 20:52 chmod.txt

如上,可同时更改ugo的权限.

示例6

# ls -l chmod.txt 
-rwxr-xr-- 1 root root 10 9月  16 20:52 chmod.txt
# chmod g=rwx chmod.txt 
# ls -l chmod.txt 
-rwxrwxr-- 1 root root 10 9月  16 20:52 chmod.txt

如上,采用g=rwx的方式,更改所属组的权限

权限的数字表示

  • r -----4
  • w -----2
  • x -----1

    所以:
    rwx = 7
    rw- = 6
    r-x = 5
    ......

示例7

# ls -l chmod.txt 
-rwxrwxr-- 1 root root 10 9月  16 20:52 chmod.txt
# chmod 764 chmod.txt 
# ls -l chmod.txt 
-rwxrw-r-- 1 root root 10 9月  16 20:52 chmod.txt

如上,采用数字更改权限的方式,rwxrw-r--对应764.

示例8

# ll testdir/
total 8
drwxr-xr-x 2 root root 4096 9月  16 21:30 ./
drwxr-xr-x 3 root root 4096 9月  16 21:30 ../
-rw-r--r-- 1 root root    0 9月  16 21:30 testfile
# chmod -R 777 testdir/
# ll testdir/
total 8
drwxrwxrwx 2 root root 4096 9月  16 21:30 ./
drwxr-xr-x 3 root root 4096 9月  16 21:30 ../
-rwxrwxrwx 1 root root    0 9月  16 21:30 testfile*

如上,chmod -R 777 testdir,-R递归修改testdir及其目录下文件的权限.

详解rwx权限
对于文件的含义

  • r:可以查看文件内容
  • w:可以修改文件内容
  • x:可以执行该文件

对目录的含义

  • r:可以列出目录中的内容
  • w:可以在目录中创建、删除文件
  • x:可以进入目录

注意:对于目录而言,有r和x权限一般同时存在

转载于:https://www.cnblogs.com/jfLin/p/9657635.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值