每天一个Linux命令(23)chmod命令
chmod命令用来变更文件或目录的权限。
在UNIX系统家族里,文件或目录权限的控制分别以读取、写入、执行3种一般权限来区分,另有3种特殊权限可供运用。用户可以使用chmod指令去变更文件与目录的权限,设置方式采用文字或数字代号皆可。符号连接的权限无法变更,如果用户对符号连接修改权限,其改变会作用在被连接的原始文件。
(1)用法:
用法: chmod [选项] [mode] 模式 文件
或 chmod [-cfvR] [--help] [--version] mode file
命令有两种用法:一种是包含字母和操作符表达式的文字设定法;另一种是包含数字的数字设定法。
(2)功能:
功能:用于改变文件或目录的访问权限,用它控制文件或目录的访问权限。
(3)参数详解:
1) -R ——recursive: 递归处理,将指令目录下的所有文件及子目录一并处理
2) -v ——verbose : 显示指令执行过程
3) --reference=<参考文件或目录>: 把指定文件或目录的所属群组全部设成和参考文件或目录的所属群组相同
4) <权限范围>+<权限设置>: 开启权限范围的文件或目录的该选项权限设置
<权限范围> -<权限设置>: 关闭权限范围的文件或目录的该选项权限设置
<权限范围>=<权限设置>: 指定权限范围的文件或目录的该选项权限设置
(4)权限范围的表示法:
1) u User 即文件或目录的拥有者
2) g Group 即文件或目录的所属群组
3) o Other 除了文件或目录拥有者或所属群组之外,其他用户皆属于这个范围
4) a All 即全部的用户,包含拥有者,所属群组以及其他用户
5) r 读取权限,数字代号为“4”
6) w 写入权限,数字代号为“2”
7) x 执行或切换权限,数字代号为“1”
8) - 不具任何权限,数字代号为“0”
9) s 特殊功能说明:变更文件或目录的权限
(5)实例:
1)[root@localhost Documents]# chmod a+x core.log 为所有用户组添加可执行权限
[root@localhost Documents]# ll -al core.log //ll -al 文件名与 ls -l 文件名貌似没啥区别
-rw-r--r--. root root 5月 : core.log
[root@localhost Documents]# ls -l core.log
-rw-r--r--. root root 5月 : core.log
[root@localhost Documents]# chmod a+x core.log
[root@localhost Documents]# ll -al core.log
-rwxr-xr-x. root root 5月 : core.log
2)[root@localhost Documents]# chmod ug+w,o-x core.log 同时为不同用户添加或删除权限
[root@localhost Documents]# ll -al core.log
-rwxr-xr-x. root root 5月 : core.log
[root@localhost Documents]# chmod ug+w,o-x core.log
[root@localhost Documents]# ll -l core.log
-rwxrwxr--. root root 5月 : core.log
3)[root@localhost Documents]# chmod g=x,o=rwx core.log 设置文件的u,g,o的三个权限。这里是设置文件所有者权限为可执行,其他用户可以读写执行,组用户权限不变
[root@localhost Documents]# ll -l core.log
-rwxrwxr--. root root 5月 : core.log
[root@localhost Documents]# chmod g=x,o=rwx core.log
[root@localhost Documents]# ls -l core.log
-rwx--xrwx. root root 5月 : core.log
4)[root@localhost Documents]# chmod -R o=--- findDir 递归的设置findDir文件夹下的文件及文件夹的其他用户权限为不具备任何权限
[root@localhost Documents]# chmod -R o=--- findDir
[root@localhost Documents]# find . -name "Dir" -print
./Dir
[root@localhost Documents]# find . -name "Dir" -exec ls -l {} \;
总用量
--w-------. root root 5月 : head_text
--w-------. root root 5月 : less1
--w-------. root root 5月 : less2
[root@localhost Documents]# ls -l Dir
总用量
--w-------. root root 5月 : head_text
--w-------. root root 5月 : less1
--w-------. root root 5月 : less2
5)[root@localhost Documents]# chmod -R u=r,g=r,o=r findDir 与 [root@localhost Documents]# chmod -R =rx Dir 等价地给ugo的用户设置权限
[root@localhost Documents]# chmod -R u=r,g=r,o=r findDir
[root@localhost Documents]# ls -l findDir
总用量
-r--r--r--. root root 5月 : p1.pdf
-r--r--r--. root root 5月 : p2.pdf
-r--r--r--. root root 5月 : t1.txt
-r--r--r--. root root 5月 : T1.txt
-r--r--r--. root root 5月 : t2.txt
-r--r--r--. root root 5月 : T2.txt
[root@localhost Documents]# ls -l Dir
总用量
--w-------. root root 5月 : head_text
--w-------. root root 5月 : less1
--w-------. root root 5月 : less2
[root@localhost Documents]# chmod -R =rx Dir //设置所有组用户权限为rw之后,以前的所有者的w权限就没了
[root@localhost Documents]# ls -l Dir
总用量
-r-xr-xr-x. root root 5月 : head_text
-r-xr-xr-x. root root 5月 : less1
-r-xr-xr-x. root root 5月 : less2
6)[root@localhost Documents]# chmod 444 find 用数字给文件设置权限
[root@localhost Documents]# chmod find
[root@localhost Documents]# ls -l find
-r--r--r--. root root 5月 : find
[root@localhost Documents]# chmod =r newlocate //两种方法等价,但同时都会将原有的权限清除
[root@localhost Documents]# ls -l newlocate
-r--r--r--. root root 5月 : newlocate
(6)其他:
Linux用户分为:拥有者、组群(Group)、其他(other)。
Linux系统中,预设的情況下,系统中所有的帐号与一般身份使用者,以及root的相关信息, 都是记录在/etc/passwd文件中。每个人的密码则是记录在/etc/shadow文件下。 此外,所有的组群名称记录在/etc/group內!
每天一个Linux命令(23)chmod命令的更多相关文章
- linux常用命令:chmod 命令
chmod命令用于改变linux系统文件或目录的访问权限.用它控制文件或目录的访问权限.该命令有两种用法.一种是包含字母和操作符表达式的文字设定法:另一种是包含数字的数字设定法. Linux系统中的每 ...
- [linux]chown和chmod命令
chown chown命令是将指定文件的拥有者改为指定的用户或组 例如: chown mail:mail test.log,把test文件指定拥有者和组都为mail chown -R mail:mai ...
- linux命令之------Chmod命令
Chmod命令 1)作用:linux和unix的文件调用权限分为三级:文件拥有者/群组/其他.利用chmod可以控制文件如何被他人所调用.(主要就是修改文件夹,文件的权限) 2)U表示该文件的拥有者, ...
- Linux命令:chmod命令
chmod命令:改变文件或目录的存取权限 #权限代号 -r 文件被读取 4 -w 文件被写入 2 -x 文件被执行 1 #权限范围 -u 文件所有者 -g 文件所有者所在组 -o 其他 -a 全部 # ...
- Linux学习历程——Centos 7 chmod命令
一.命令介绍 chmod 命令,是Linux管理员最常用的命令之一,用于修改文件或目录的访问权限. Linux系统中,每一个文件都有文件所有者和所属群组,并且规定文件的所有者,所属群组,以及其他人队问 ...
- Redis 的键命令、HyperLogLog 命令、脚本命令、连接命令、服务器命令
Redis 的键命令.HyperLogLog 命令.脚本命令.连接命令.服务器命令 Redis 的键命令 Redis 的键命令主要用于管理 Redis 的键,如删除键.查询键.修改键及设置某个键等. ...
- 每天一个linux命令(23):Linux 目录结构
对于每一个Linux学习者来说,了解Linux文件系统的目录结构,是学好Linux的至关重要的一步.,深入了解linux文件目录结构的标准和每个目录的详细功能,对于我们用好linux系统只管重要,下面 ...
- 每天一个linux命令(27):linux chmod命令
chmod命令用于改变linux系统文件或目录的访问权限.用它控制文件或目录的访问权限.该命令有两种用法.一种是包含字母和操作符表达式的文字设定法:另一种是包含数字的数字设定法. Linux系统中的每 ...
- 每天一个linux命令(20):linux chmod命令
chmod命令用于改变linux系统文件或目录的访问权限.用它控制文件或目录的访问权限.该命令有两种用法.一种是包含字母和操作符表达式的文字设定法:另一种是包含数字的数字设定法. Linux系统中的每 ...
随机推荐
- Mysql5.6压缩包安装到windows&& 卸载命令
1.根目录下有一个my-default.ini,复制一下,重命名为my.ini,然后改一下my.ini为符合你情况的配置,一般只需要改basedir .datadir .port ,注意前边的井号去掉 ...
- threw load() exception java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet(maven项目git后)
maven项目git全新项目后启动服务出现的, 错误原因: 进入到tomcat的部署路径.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpw ...
- $on、$emit和$broadcast的使用
$emit只能向parent controller传递event与data( $emit(name, args) ) $broadcast只能向child controller传递event与data ...
- Atitit.5gl 第五代语言编程语言 PROLOG教程 人工智能语言的标准 与实现
Atitit.5gl 第五代语言编程语言 PROLOG教程 人工智能语言的标准 与实现 1. 第五代语言就是自然语言又被称为知识库语言或人工智能语言,1 2. 人工智能语言特点2 2.1. 试探法2 ...
- Swagger跨域访问
我们用springboot开发完后,需要前端vue用swagger跨域,默认是不能跨域的,所以需要我们后台设置跨域访问,将下面代码完整复制即可. 在springboot项目中新建class : Cor ...
- Spring 中的Null-Safety
之前一直在某些代码中看到过使用@Nullable 标注过的注释,当时也没有在意到底是什么意思,所以这篇文章来谈谈Spring中关于Null的那些事. 在Java中不允许让你使用类型表示其null的安全 ...
- Win7 设置、访问共享文件夹
一.设置共享文件夹 右键点击文件夹,打开“属性”窗口,选择“共享”选项卡 点击“共享”按钮,打开“文件共享”窗口,在下拉列表中选择账户,点“添加”,最后点“共享”按钮. 二.访问 \\192.168. ...
- git add -A使用说明
git help add -A, --all Like -u, but match <filepattern> against files in the workin ...
- iOS将Unity导出的Xcode工程导入到另一个Xcode项目, 及常见报错的解决方法
demo下载地址 http://pan.baidu.com/s/1pLcpKpl 1.Unity导出工程时设置bundle id要与项目一致 2.修改bit code为NO 3.删除Main.stor ...
- Eclipse搭建C++开发环境
http://jingyan.baidu.com/article/456c463b67b4310a59314468.html