在 joomla 根目录中设置文件和文件夹权限的推荐方法如下(来自 help.ubuntu 网站)
cd /var/www/joomla/
sudo find . -type f -exec chmod 644 {} \;
sudo find . -type d -exec chmod 755 {} \;
有人能解释一下上面两个 chmod 语句中的 {} 和 \ 的用途吗?
答案1
该find
命令返回文件列表,参数-exec
对列出的每个文件执行命令chmod 644
。括号允许用户指定在命令中使用列出的文件名的位置...
用于\;
指定命令的结束(在本例中为chmod
命令的结束)
看man find
:
-exec command ;
Execute command; true if 0 status is returned. All following
arguments to find are taken to be arguments to the command until
an argument consisting of ';' is encountered. The string '{}'
is replaced by the current file name being processed everywhere
it occurs in the arguments to the command, not just in arguments
where it is alone, as in some versions of find. Both of these
constructions might need to be escaped (with a '\') or quoted to
protect them from expansion by the shell. See the EXAMPLES sec-
tion for examples of the use of the '-exec' option. The speci-
fied command is run once for each matched file. The command is
executed in the starting directory. There are unavoidable
security problems surrounding use of the -exec option; you
should use the -execdir option instead.