加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

权限管理命令--chmod

发布时间:2020-12-14 03:45:47 所属栏目:大数据 来源:网络整理
导读:权限管理命令--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 #

权限管理命令--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权限一般同时存在

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读