Python的os.chown()
方法將路徑的所有者和組ID更改為數字uid
和gid
。 要使其中一個ID不變,請將其設置為-1
。要設置所有權,需要超級用戶許可權。
語法
以下是chown()
方法的語法 -
os.chown(path, uid, gid)
參數
- path − 這是需要設置所有者ID和組ID的路徑。
- uid − 這是為檔設置的所有者ID。
- gid − 這是為檔設置的組ID。
返回值
- 此方法不返回任何值。
示例
以下示例顯示了chown()
方法的用法。
#!/usr/bin/python3
import os, sys
# Assuming /tmp/foo.txt exists.
# To set owner ID 100 following has to be done.
os.chown("/tmp/foo.txt", 100, -1)
print ("Changed ownership successfully!!")
執行上面代碼後,將得到以下結果 -
Changed ownership successfully!!
上一篇:
Python os模組方法
下一篇:
Python異常處理