linux系统中chmod命令
1、linux系统中文件和目录的权限
按照用户可分为所有者、所属组和其他人。
所有者用u代表(user)
所属组用g代表(group)
其他人用o代表(other)
按照具体的权限可以分为可读、可写、可执行、无权限
可读用r代表(read),用数字4表示
可写用w代表(write),用数字2表示
可执行用x代表(execute?),用数字1表示
2、linux中使用ll -l 、ls -l 、ls -ld等命令查看文件或目录权限
例如:
[root@linuxprobe test]# ll
total 0
-rw-r--r--. 1 root root 0 Oct 20 20:59 a.txt
drwxr-xr-x. 2 root root 6 Oct 20 21:00 test01
3、linux系统中使用chmod命令修改文件和目录的权限
用法chmod [选项} 文件,示例:
[root@linuxprobe test]# ll
total 0
-rw-r--r--. 1 root root 0 Oct 20 20:59 a.txt
drwxr-xr-x. 2 root root 6 Oct 20 21:00 test01
[root@linuxprobe test]# chmod u+x a.txt ## 所有者增加执行权限
[root@linuxprobe test]# ll
total 0
-rwxr--r--. 1 root root 0 Oct 20 20:59 a.txt
drwxr-xr-x. 2 root root 6 Oct 20 21:00 test01
[root@linuxprobe test]# chmod u-x,g+w test01/ ## 所有者减去执行权限,同时所属组增加写得全选
[root@linuxprobe test]# ll
total 0
-rwxr--r--. 1 root root 0 Oct 20 20:59 a.txt
drw-rwxr-x. 2 root root 6 Oct 20 21:00 test01
[root@linuxprobe test]# chmod u=rw,g=r,o=x a.txt ## 直接按照所有者、所属组、其他人赋予权限
[root@linuxprobe test]# ll
total 0
-rw-r----x. 1 root root 0 Oct 20 20:59 a.txt
drw-rwxr-x. 2 root root 6 Oct 20 21:00 test01
[root@linuxprobe test]# chmod 421 test01/ ## 直接使用数字赋予权限 4表示所有者有读的权限,2表示所属组有写的权限,1代表其他人具有执行的权限
[root@linuxprobe test]# ll
total 0
-rw-r----x. 1 root root 0 Oct 20 20:59 a.txt
dr---w---x. 2 root root 6 Oct 20 21:00 test01
[root@linuxprobe test]# chmod 777 a.txt ## 所有者、所属组、其他人都具有可读、可写、可执行的权限
[root@linuxprobe test]# ll
total 0
-rwxrwxrwx. 1 root root 0 Oct 20 20:59 a.txt
dr---w---x. 2 root root 6 Oct 20 21:00 test01
3、修改目录权限时,加 -R参数表示递归
[root@linuxprobe test]# mkdir test01 test02 ## 测试目录
[root@linuxprobe test]# touch test01/a.txt ##测试文件
[root@linuxprobe test]# touch test02/b.txt ##测试文件
[root@linuxprobe test]# ll
total 0
drwxr-xr-x. 2 root root 18 Oct 20 21:15 test01
drwxr-xr-x. 2 root root 18 Oct 20 21:15 test02
[root@linuxprobe test]# ls -l test01/a.txt
-rw-r--r--. 1 root root 0 Oct 20 21:15 test01/a.txt
[root@linuxprobe test]# ls -l test02/b.txt
-rw-r--r--. 1 root root 0 Oct 20 21:15 test02/b.txt
[root@linuxprobe test]# chmod 777 test01/
[root@linuxprobe test]# chmod -R 777 test02/ ## 添加 -R参数
[root@linuxprobe test]# ll
total 0
drwxrwxrwx. 2 root root 18 Oct 20 21:15 test01
drwxrwxrwx. 2 root root 18 Oct 20 21:15 test02
[root@linuxprobe test]# ls -l test01/a.txt
-rw-r--r--. 1 root root 0 Oct 20 21:15 test01/a.txt
[root@linuxprobe test]# ls -l test02/b.txt ## test02目录下的b.txt也赋予了777的权限
-rwxrwxrwx. 1 root root 0 Oct 20 21:15 test02/b.txt
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律