files_to_change_permissions = [ '/etc/passwd', '/etc/group', '/etc/shadow' ] for file_path in files_to_change_permissions: command = 'chmod 644 {}'.format(file_path) subprocess.call(command, shell=True)
时间: 2024-04-14 12:25:46 浏览: 20
你的代码几乎正确,只是在使用`subprocess.call`时需要将命令作为字符串列表传递。以下是修正后的代码:
```python
import subprocess
files_to_change_permissions = [
'/etc/passwd',
'/etc/group',
'/etc/shadow'
]
for file_path in files_to_change_permissions:
command = ['chmod', '644', file_path]
subprocess.call(command)
```
上述代码将遍历`files_to_change_permissions`列表中的文件路径,并使用`chmod`命令将文件权限更改为644。
请确保你具有足够的权限来更改文件权限,并将需要更改权限的文件路径添加到`files_to_change_permissions`列表中。运行代码后,文件的权限将被更改为644。
相关问题
python2实现效果 ``` chmod 644 /etc/passwd chmod 644 /etc/group chmod 400 /etc/shadow ```
以下是使用Python 2实现修改文件权限的示例代码:
```python
import os
# 修改文件权限函数
def change_permissions(file_path, permissions):
try:
# 将权限转换为八进制
permissions = int(permissions, 8)
# 修改文件权限
os.chmod(file_path, permissions)
print("已修改文件权限:" + file_path)
except Exception as e:
print("修改文件权限时出错:" + str(e))
# 文件路径和权限列表
file_permissions = [
("/etc/passwd", "644"),
("/etc/group", "644"),
("/etc/shadow", "400")
]
# 遍历文件路径和权限列表
for file_path, permissions in file_permissions:
change_permissions(file_path, permissions)
```
请注意,这是使用Python 2编写的代码,对应的Python 3代码可能会有一些差异。另外,执行这段代码需要具有足够的权限,通常需要以root用户身份运行。
denied { getattr } for path="/storage/emulated/0/Android/data/com.mxy.mdm_demo/files/
Unfortunately, as an AI language model, I do not have the context to fully understand the situation you are experiencing. However, based on the error message you provided, it seems that your application is being denied access to a specific file path on an Android device. This could be due to several reasons, such as permissions not being granted or the file being locked by another process. Please provide more information or consult the Android developer documentation for further assistance.