Python的os.chown()
方法將路徑的所有者和組ID更改為數位uid
和gid
。 要使其中一個ID不變,請將其設定為-1
。要設定所有權,需要超級使用者許可權。
語法
以下是chown()
方法的語法 -
os.chown(path, uid, gid)
引數
返回值
範例
以下範例顯示了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!!