python - chmod 777 到 python 脚本

标签 python linux chmod

尝试将 linux cmd 转换为 python 脚本

Linux 命令:

chmod 777 file1 file1/tmp file2 file2/tmp file3 file3/tmp

我知道 os.chmod(file, 0777) 但我不确定如何在上面的行中使用它。

最佳答案

os.chmod 将单个文件名作为参数,因此您需要遍历文件名并应用 chmod:

files = ['file1', 'file1/tmp', 'file2', 'file2/tmp', 'file3', 'file3/tmp']
for file in files:
    os.chmod(file, 0o0777)

顺便说一句,我不确定为什么要将权限位设置为 777 —— 这是自找麻烦。您应该选择尽可能严格的权限位。

关于python - chmod 777 到 python 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49308355/

相关文章:

linux - 在我的 .tcshrc 文件中以只读模式在 Linux 上为 emacs 创建别名

c - 防止线程写入同一文件

linux - 使用 "sudo chmod 444 etc"更改目录权限后无法编辑目录权限

python - 在嵌套(while)循环中的什么地方放置变量?

linux - 如果导入“C”,则无法交叉编译

linux - 撤消错误的 chmod

chmod 无法授予所有权限

Python Pillow 透明 gif 不起作用

python - 如何提高以下 python 代码的性能

python - 通过将窗口大小增加到周期来计算百分比变化