Python方法fchown()将fd给定的文件的所有者和组ID更改为数字uid和gid。要保持其中一个ID不变,请将其设置为-1。
注意-此方法从Python2.6开始可用。
链接:https://www.learnfk.comhttps://www.learnfk.com/python/os-fchown.html
来源:LearnFk无涯教程网
os.fchown(fd, uid, gid);
fd - 这是需要为其设置所有者ID和组ID的文件描述符。
uid - 这是要为文件设置的所有者ID。
gid - 这是要为文件设置的组ID。
以下示例显示fchown()方法的用法。
#!/usr/bin/python import os, sys, stat # Now open a file "/tmp/foo.txt" fd=os.open( "/tmp", os.O_RDONLY ) # Set the user Id to 100 for this file. os.fchown( fd, 100, -1) # Set the group Id to 50 for this file. os.fchown( fd, -1, 50) print "Changed ownership successfully!!" # Close opened file. os.close( fd )
当无涯教程运行上面的程序时,它产生以下输出-
Changed ownership successfully!!
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)