Linux基本命令-chmod
chmod命令用来变更文件或目录的权限。在UNIX系统家族里,文件或目录权限的控制分别以读取、写入、执行3种一般权限来区分,另有3种特殊权限可供运用。用户可以使用chmod指令去变更文件与目录的权限,设置方式采用文字或数字代号皆可。符号连接的权限无法变更,如果用户对符号连接修改权限,其改变会作用在被连接的原始文件。
权限范围的表示法如下:
- u:user,文件或目录的拥有者
- g:group,文件或目录的所属群组
- o:other,除了文件或目录拥有者或所属群组之外,其他用户皆属于这个范围
- a:all,全部的用户,包含拥有者,所属群组以及其他用户
- r:read,读取权限,数字代号为“4”
- w:write,写入权限,数字代号为“2”
- x:执行或切换权限,数字代号为“1”
- -:不具有任何权限,数字代号为“0”
- s:特殊功能说明:变更文件或目录的权限
语法
chmod (选项) (参数)
选项
-c或——changes:效果类似“-v”参数,但仅回报更改的部分;
-f或--quiet或——silent:不显示错误信息;
-R或——recursive:递归处理,将指令目录下的所有文件及子目录一并处理;
-v或——verbose:显示指令执行过程;
--reference=<参考文件或目录>:把指定文件或目录的所属群组全部设成和参考文件或目录的所属群组相同;
<权限范围>+<权限设置>:开启权限范围的文件或目录的该选项权限设置;
<权限范围>-<权限设置>:关闭权限范围的文件或目录的该选项权限设置;
<权限范围>=<权限设置>:指定权限范围的文件或目录的该选项权限设置;
参数
权限模式:指定文件的权限模式;
文件:要改变权限的文件。
实例
Linux用 户分为:拥有者、组群(Group)、其他(other),Linux系统中,预设的情況下,系统中所有的帐号与一般身份使用者,以及root的相关信 息, 都是记录在/etc/passwd文件中。每个人的密码则是记录在/etc/shadow文件下。 此外,所有的组群名称记录在/etc/group內!
linux文件的用户权限的分析图

例如:rwxrw-r--
r=可读 //值为4
w=可写 //值为2
x=可执行 //值为1
-=无权限 值为0
命令执行:
[root@localhost ~]# touch test.txt
[root@localhost ~]# ll
total
-rw-------. root root Apr : anaconda-ks.cfg
-rw-r--r--. root root Jun : test.txt
我们可以看到新建的test.txt文档具有的权限:rw-r--r--,对应的值为644。
[root@localhost ~]# chmod u=rwx,g=rw,o=r test.txt
[root@localhost ~]# ll
total
-rw-------. root root Apr : anaconda-ks.cfg
-rwxrw-r--. root root Jun : test.txt
现在的权限为rwxrw-r--,权限值为764.
[root@localhost ~]# chmod u-x,g+x-w,o+x test.txt
[root@localhost ~]# ll
total
-rw-------. root root Apr : anaconda-ks.cfg
-rw-r-xr-x. root root Jun : test.txt
现在的权限是rw-r-xr-x,权限值为655.
[root@localhost ~]# chmod a=r test.txt
[root@localhost ~]# ll test.txt
-r--r--r--. root root Jun : test.txt
现在的权限是r--r--r--,权限值为444.
[root@localhost ~]# chmod a+x test.txt
[root@localhost ~]# ll test.txt
-r-xr-xr-x. root root Jun : test.txt
现在的权限是r-xr-xr-x,权限值为555.
[root@localhost ~]# chmod test.txt
[root@localhost ~]# ll test.txt
-r--r-----. root root Jun : test.txt
通过值更改权限后,同样根据值的换算得到文件权限:r--r-----,值为440
[root@localhost ~]# chmod test.txt
[root@localhost ~]# ll test.txt
-rwxrwxrwx. root root Jun : test.txt
上面是777权限。rwxrwxrwx.
递归参数
[root@localhost ~]# ls -l
total
-rw-------. root root Apr : anaconda-ks.cfg
drwxr-xr-x. root root Jun : test
[root@localhost ~]# ls -l test
total
-r--r--r--. root root Jun : test1
--w--w--w-. root root Jun : test2
---x--x--x. root root Jun : test3
当前test目录为731权限,test目录下的test1为444权限,test2为222权限,test3为111权限。现在进行递归权限管理:
[root@localhost ~]# chmod -R test
[root@localhost ~]# ls -l
total
-rw-------. root root Apr : anaconda-ks.cfg
drwxrwxrwx. root root Jun : test
-rwxrwxrwx. root root Jun : test.txt
[root@localhost ~]# ls -l test
total
-rwxrwxrwx. root root Jun : test1
-rwxrwxrwx. root root Jun : test2
-rwxrwxrwx. root root Jun : test3
通过执行chmod -R 777 test命令,test目录的权限以及其下的所有文件全部递归调整权限为777。
Linux基本命令-chmod的更多相关文章
- Linux常用基本命令(chmod)
chmod命令用来改变文件或者目录的权限,只有文件的属主和超级用户才能够执行这个命令 格式: chmod [option] [mode] [file] >常用参数选项 -R : 递归修改目录以及 ...
- linux 基本命令 [转]
linux 基本命令 1.ls (list 显示当前目录下文件和目录 ls -l 详细显示 =ll ) [root@linux ~]# ls [-aAdfFhilRS] 目录名称 [root@lin ...
- 剑指Offer——知识点储备--Linux基本命令+Makefile
剑指Offer--知识点储备–Linux基本命令 1.linux下查看进程占用cpu的情况(top): 格式 top [-] [d delay] [q] [c] [S] [s] [i] [n] 主要参 ...
- Linux学习总结(9)——Linux 新手必知必会的 10 条 Linux 基本命令
Linux 对我们的生活产生了巨大的冲击.至少你的安卓手机使用的就是 Linux 核心.尽管如此,在第一次开始使用 Linux 时你还是会感到难以下手.因为在 Linux 中,通常需要使用终端命令来取 ...
- linux 基本命令 1
Linux基本命令(一) 目标 熟练使用 Linux常用的命令 ls 查看文件 clear 清空 cd pwd mkdir touch rm cp mv tree chmod find gr ...
- 【Linux基础总结】Linux基本命令
Linux基本命令 Linux系统下的文件类型.权限.所属用户与组 文件类型 - (文件) d(目录) ->类似windows系统下的文件夹 l (链接) ->类似windows系统下的快 ...
- Linux基本命令及编程环境实验
目录 一.Linux基本命令详细汇总 1.目录及文件相关命令 2.系统信息查询 3.文件操作(统计.过滤.搜索.权限) 4.其他命令 二.Linux终端上vi命令编程 1.进入vi命令模式 2.vi编 ...
- Linux基本命令(一)
Linux基本命令 编辑器 vim编译器 Gnu工具链-gcc调试器 GDB操作系统是用C来写的 系统编程 (核心骨架 80%) 文件I/O 文件系统 进程{ 进程控制原语.进程间通信.进程间关系 信 ...
- 2 、Linux基本命令-ls-pwd-cd-date-hwclock
Linux基本命令: 1.ls-查看目录下的文档 语法: ls 目录 注: .当前目录 ..上级目录 如:ls /etc/ 相关参数: -l 显示详细信息 ls /etc/ -l -a 显示隐藏的 ...
随机推荐
- python:序列化与反序列化(json、pickle、shelve)
本节内容 前言 json模块 pickle模块 shelve模块 总结 一.前言 1. 现实需求 每种编程语言都有各自的数据类型,其中面向对象的编程语言还允许开发者自定义数据类型(如:自定义类),Py ...
- nginx目录学习
目录 一. Nginx 基础知识 二. Nginx 安装及调试 三. Nginx Rewrite 四. Nginx Redirect 五. Nginx 目录自动加斜线: 六. Nginx Locati ...
- Ext this.getView(...).saveDocumentAs is not a function
一.前言 Ext 导出数据,根据官网的代码,报:this.getView(...).saveDocumentAs is not a function 的问题. 参考:Ext Export not wo ...
- Source Insight快捷键
常用使用技巧 按住"ctrl", 再用鼠标指向某个变量(或函数),点击一下,就能进入这个变量(或函数)的定义. 快捷键 "Alt + F12",可以让显示界面中 ...
- [转帖]Oracle数据库lob大对象数据类型字段总结,值得收藏
Oracle数据库lob大对象数据类型字段总结,值得收藏 原创 波波说运维 2019-07-11 00:02:00 https://www.toutiao.com/i67108943269703357 ...
- K8S从入门到放弃系列-(14)Kubernetes集群Dashboard部署
Dashboard是k8s的web界面,用户可以用 Kubernetes Dashboard 部署容器化的应用.监控应用.并对集群本身进行管理,在 Kubernetes Dashboard 中可以查看 ...
- Redis 常用命令学习二:字符串类型命令
1.赋值与取值命令 127.0.0.1:6379> set foo helloredis OK 127.0.0.1:6379> get foo "helloredis" ...
- C++实现16进制字符串转换成int整形值
开发中经常需要把16进制字符串转换成整形,写了个个代码供大家参考下: #include <stdio.h> #include <string.h> //字符转换成整形 int ...
- php类常量
类常量类常量可以使用define定义,也可用const定义,但是在类的内部,只允许用const定义,类常量不能更新,也不能删除类常量通常是大写的,两个单词之间用下滑线连接,如MY_NATION类常量在 ...
- python学习-26 函数作用域
举例说明: 1. name = 'john' def foo(): name = 'xiaomming' def bar(): print(name) return bar a=foo() print ...