Commands for changing ownership of a file

Michael Poeltl michael.poeltl at univie.ac.at
Mon Aug 15 03:58:48 CEST 2011


in python-3.2.1 I'm using os.system() again, from time to time
maybe that's the one you were looking for?

>>> os.system('chown user:group /tmp/f')
0
>>> os.system('ls -l /tmp/f')
-rw-r--r-- 1 user group 0 Aug 15 03:52 /tmp/f

and besides os.chown() (where you ned the uid and gid), you could also use subprocess.call() or subprocess.Popen()

regards
Michael
* Jason Hsu <jhsu802701 at gmail.com> [2011-08-15 01:15]:
> I have a script that I execute as root, but I need to change the
> ownership of the files created in the script to that of my username.
> In GNU Bash, the command is something like "chown myusername:users".
> What's the equivalent Python command?  I know that there is a command
> that uses numbers for the username and group, but is there a command
> that would allow me to use "myusername" and "users" instead of numbers?
> -- 
> http://mail.python.org/mailman/listinfo/python-list
> 

-- 
Michael Poeltl
Computational Materials Physics      voice: +43-1-4277-51409
Univ. Wien, Sensengasse 8/12         fax:   +43-1-4277-9514 (or 9513) 
A-1090 Wien, AUSTRIA   cmp.mpi.univie.ac.at 
--------------------------------------------------------------------------------
slackware-12.2/ubuntu-10.10 | vim-7.3 | python-3.2.1 | mutt-1.5.18 | elinks-0.12
--------------------------------------------------------------------------------



More information about the Python-list mailing list