以下命令是什么:chmod -r?

问题描述 投票:0回答:1

此命令在Linux终端中起什么作用?

chmod -r /home/daria/photos/

我有这个问题,因为没有错误

linux ubuntu unix terminal chmod
1个回答
0
投票

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的手册页没有解释这一点,这使某些用户感到困难,但是一旦您知道了这一点,就不能不知道这一点了:)

© www.soinside.com 2019 - 2024. All rights reserved.