linux - 创建文件或目录时可以设置权限吗?

标签 linux command-line permissions file-permissions chmod

我可以在使用单个命令创建文件/目录时设置权限,还是必须先创建文件/目录然后使用 chmod 设置其权限?

比如做这样的事情

// for directories
mkdir 755 test 

// for files
touch 644 test/my_file.php

最佳答案

对于文件,尝试使用 install 命令:

$ install -m 644 /test/path/ myfile.php

对于文件夹,mkdir-m 参数:

$ mkdir -m 755 test

您可能必须以 sudo 的形式执行它。

关于linux - 创建文件或目录时可以设置权限吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30284654/

相关文章:

python - 如何使用 Distutils 让 Python 脚本作为简单的 linux 命令运行?

python - 在 Python OptParse 中解析任意数量的参数

bash - 从 bash 的新 Google Chrome 浏览器 session 中获取 "user agent"字符串

python-3.x - 共享点文件夹应用程序权限 - 未经授权

c# - 在ASP.NET中,使用什么来管理角色和分配给角色的权限?

linux - Bash 脚本第 106 行 : syntax error: unexpected end of file

php - 很简单的mod_rewrite问题

linux - 从 Postgresql 9.1 升级到 9.3 时为 "cannot write to log file pg_upgrade_internal.log"

hadoop - 是否可以从命令行读取orcserde hadoop文件?

iOS 重置授权访问提醒