如何使用python设置给定目录名称的文件夹中所有文件的权限?

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

不言自明。但基本上我正在尝试

shutil.rmtree
~/.ssh
并且私钥具有限制性的读/写权限。

我不想对密钥的名称做出任何假设,所以我想 chmod 777

~/.ssh
中的所有内容,然后
shutil.rmtree
它。我该怎么做?

python python-3.x chmod shutil
1个回答
0
投票
sudo chmod -R 777 ~/.ssh

这应该可以解决问题

编辑:抱歉我没有阅读标题中的Python。我认为你可以在嵌套 for 循环中使用它。

for root, dirs, files in os.walk(ssh_dir):
    for d in dirs:
        os.chmod(os.path.join(root, d), 0o777)
    for f in files:
        os.chmod(os.path.join(root, f), 0o777)
© www.soinside.com 2019 - 2024. All rights reserved.