此命令在Linux终端中起什么作用?
chmod -r /home/daria/photos/
我有这个问题,因为没有错误
chmod
是一个实用程序,用于更改文件或目录的permissions
。您可以使用ls -l /path/to/file
命令观察chmod的变化。
❯ echo "XYZ" > /tmp/abc # Create a new file named abc
❯ l /tmp/abc # List the permissions of /tmp/abc
-rw-r--r-- 1 abdulkarim wheel 4B Apr 3 13:17 /tmp/abc
❯ cat /tmp/abc # Display the contents of the file
XYZ
❯ chmod -r /tmp/abc # remove read permissions for User, Group and Others
❯ l /tmp/abc # Notice the read perms are gone
--w------- 1 abdulkarim wheel 4B Apr 3 13:17 /tmp/abc
❯ cat /tmp/abc # We can no longer cat the file!
cat: /tmp/abc: Permission denied
因此,命令chmod -r /path/to/file
将撤消所有人的读取权限。同样,chmod +r
将授予所有人读取权限。
chmod的手册页没有解释这一点,这使某些用户感到困难,但是一旦您知道了这一点,就不能不知道这一点了:)