设为首页 加入收藏

TOP

Linux快速入门(三)Linux文件管理(二)
2023-07-23 13:31:26 】 浏览:36
Tags:Linux 文件管

Linux文件权限

chmod

在说文件权限之前,先介绍一下Linux下关于文件的一些知识:

root@ubuntu:~# ll
total 48
drwx------  6 root root 4096 Aug 29 15:29 ./
drwxr-xr-x 19 root root 4096 Jul 18 21:50 ../
-rw-------  1 root root   76 Aug 29 10:06 .bash_history
-rw-r--r--  1 root root 3106 Oct 15  2021 .bashrc
drwx------  3 root root 4096 Jul  8 03:01 .cache/
-rw-------  1 root root   20 Jul  8 03:08 .lesshst
-rw-r--r--  1 root root  161 Jul  9  2019 .profile
drwx------  2 root root 4096 Jul  8 02:41 .ssh/
-rw-------  1 root root 2713 Aug 29 15:29 .viminfo
-rw-r--r--  1 root root   40 Aug 29 15:29 1.txt
-rw-r--r--  1 root root    0 Aug 29 15:22 2.txt
-rw-r--r--  1 root root    0 Aug 29 15:06 3.txt
-rw-r--r--  1 root root    0 Aug 29 15:22 4.txt
drwxr-xr-x  2 root root 4096 Aug 29 15:18 Music/
drwx------  3 root root 4096 Jul  8 03:05 snap/

我们使用ll查看文件的时候,可以看到文件的详细信息,文件详细信息的第一列是文件的格式,d表示该文件是一个目录,-表示该文件是一个普通文件,c表示为串行端口设备,如键盘鼠标等。
详细信息中的第二到第四个字符是文件所有者对该文件拥有的权限,r表示读权限,通常使用数字4表示,w表示写文件,通常使用数字2表示,x表示执行权限,通常使用数字1表示,如果拥有对应权限就会有对应的字符,如果是-表示没有对应权限。
接下来的三个字符是当前用户所在组对该文件拥有的权限,再接着的三个字符是其他用户对该文件的权限。

这时我们想对文件的权限进行修改时就可以通过chmod命令加上需要修改的权限对应的数字组合进行修改,比如我想修改4.txt的属性为只允许我自己拥有读写权限,其余人没有任何权限,就可以使用chomd 600 文件名,600中的64+2得来,即读权限+写权限,6对应的是前三个字符当前用户的权限,第二个0对应的是当前用户所属组的权限,第三个0对应的是其他用户对于这个文件的权限。

root@ubuntu:~/Music# ll
total 12
drwxr-xr-x 2 root root 4096 Aug 29 15:37 ./
drwx------ 6 root root 4096 Aug 29 15:37 ../
-rw-r--r-- 1 root root   40 Aug 29 15:29 1.txt
-rw-r--r-- 1 root root    0 Aug 29 15:22 2.txt
-rw-r--r-- 1 root root    0 Aug 29 15:06 3.txt
-rw-r--r-- 1 root root    0 Aug 29 15:22 4.txt
root@ubuntu:~/Music# chmod 600 4.txt 
root@ubuntu:~/Music# ll
total 12
drwxr-xr-x 2 root root 4096 Aug 29 15:37 ./
drwx------ 6 root root 4096 Aug 29 15:37 ../
-rw-r--r-- 1 root root   40 Aug 29 15:29 1.txt
-rw-r--r-- 1 root root    0 Aug 29 15:22 2.txt
-rw-r--r-- 1 root root    0 Aug 29 15:06 3.txt
-rw------- 1 root root    0 Aug 29 15:22 4.txt
首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Linux快速入门(五)Linux系统管理 下一篇Linux快速入门(一)Linux基础知识

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目