我想给一个目录加上可读权限,但是不小心手残了。写成了
sudo chmod -R -o+r files
中间多了个写-(横杠)。 我改正了之后
sudo chmod -R o+r files
又执行了一遍。 然后我就 cd 不进去了。提示"Permission denied".
我想那好吧。我给就给个最开放的权限
sudo chmod -R 777 files
这下是可以 cd 进去了,但是一直给最开放的权限也不行呀。想想一下还是把可执行权限去掉吧,执行了
sudo chmod -R o-x files
然后奇怪的事发生了。我又 cd 不进去了。为什么我只是撤掉了执行权限但是读权限也没了。
与没有知道的大佬,帮忙给个提示。
1 fxplay 2018-07-13 16:57:20 +08:00 ![]() 删除 新建 给权限 不要太纠结 |
2 WenhanWu 2018-07-13 17:00:12 +08:00 ![]() sudo chmod -R 755 files |
![]() | 3 topbandit 2018-07-13 17:11:22 +08:00 ![]() 进目录需要执行权限 |
![]() | 4 Osk 2018-07-13 17:13:48 +08:00 via Android ![]() r:你可以 ls dir 看里面的文件。 x:你可以 cd 到该文件夹,及其子文件夹,ls 子文件的内容也需要 x。 一般目录都是 rx 同时有的,特殊情况只给 x 权限,比如 android 的 /data 分区似乎是如此,这样就能限制 app 读取 data 里面的文件列表,但又不影响 app 对自己数据文件夹的操作 |
![]() | 5 Lpl 2018-07-13 17:24:28 +08:00 ![]()  执行那个错误的命令的时候,就把用户的 x 权限搞丢了。后来又没上去,所有就 Permission denied 咯 这个链接: https://wiki.archlinux.org/index.php/File_permissions_and_attributes ``` - The directory cannot be accessed with cd. x The directory can be accessed with cd ``` |
![]() | 6 mrzx 2018-07-13 17:26:58 +08:00 ![]() 要 CD 进去,除了 r 可读权限,还需要 x 执行权限 |
![]() | 7 mrzx 2018-07-13 17:31:19 +08:00 还是国内书籍理解的问题。 linux 下,什么 cd,ls 这些严格意思上来说不能叫命令。 实际上编辑好的二进制小工具。你可以理解成就是一堆小软件 通过 bash shell 自动调用 /bin /sbin 下的工具。 不相信,你随便删除一个,看看你所谓的“命令”还能执行吗? 实际是 CD 是个工具,对文件格式下的目录做出了相对应的操作。 |
![]() | 8 AlisaDestiny OP |
![]() | 10 AlisaDestiny OP @Lpl 哈哈,我还奇怪呢,上层目录权限是 drw-r--r--没有执行权限的时候我用 ls 命令发现可以看到文件名,但是 其他列都是问号。我还以为搞出啥问题了呢。 |
![]() | 11 Tyanboot PRO @mrzx 理解的确是一个大问题,不过命令这个也不能怪翻译,毕竟 shell 爆的就是 command not found,一般也不会给爆诸如“ executable not found “什么的。 |
![]() | 12 geelaw 2018-07-13 17:56:50 +08:00 |
![]() | 13 momocraft 2018-07-13 18:01:38 +08:00 别乱自己定义好不.. "ls 不是命令" "cd 是个工具" 都讲得出 人才 |
![]() | 15 mrzx 2018-07-13 18:10:56 +08:00 @momocraft 我理解的是,命令本身就是集成在 shell 的,而不是和 shell 独立开来的某个程序,但是像 ls,cp 这类的,我一直认为是个独立的二进制工具,当文件删除的时候,就无法在 bash 里调用了。不过今天听 geelaw 一说,有了更深层次的理解。 比如 ls root@simon:~# ls -l /bin | grep ls -rwxr-xr-x 1 root root 31464 Feb 22 2017 false -rwxr-xr-x 1 root root 130736 Feb 22 2017 ls -rwxr-xr-x 1 root root 81376 Mar 7 13:29 lsblk lrwxrwxrwx 1 root root 4 Dec 25 2016 lsmod -> kmod 一旦删除 ls,你无论如何无法 ls 这个命令。 |
![]() | 17 momocraft 2018-07-13 18:48:33 +08:00 没有这个文件也可以定义叫 ls 的 alias 或函数。考虑一下: 为什么 "aabbcc 回车" 的错误信息是 **command** not found,而 "/bin/aabbcc 回车" 的错误信息是 No such file or directory |
![]() | 18 lance6716 2018-07-13 18:50:15 +08:00 via Android Unix 作业刚写完一个 shell … cd 是 shell 实现的,ls 是系统提供的 |
![]() | 19 laodao1990 2018-07-13 19:05:32 +08:00 #4 楼是明白人。 想了解这个,楼主可以查询 linux 里的数据存储问题. 关键字:inode 意识到目录也是文件,知道目录的 inode 里面都有什么,对应的就能了解对目录执行 ls,cd 都需要什么权限。 建议看看鸟哥的 linux 私房菜。 |
![]() | 20 PHPer233 2018-07-13 19:11:31 +08:00 via iPhone 你要 cd 进某个目录,必须具有 x 权限。我不知道为什么,但事实就是这样。 |
![]() | 21 z123 2018-07-13 19:34:25 +08:00 三楼正解:cd 进目录需要 x 权限 |
22 Vitameans 2018-07-14 00:08:07 +08:00 via iPhone The execute permission grants the ability to execute a file. This permission must be set for executable programs, in order to allow the operating system to run them. When set for a directory, the execute permission is interpreted as the search permission: it grants the ability to access file contents and meta-information if its name is known, but not list files inside the directory, unless read is set also. Source: https://en.m.wikipedia.org/wiki/File_system_permissions#Permissions |