os.chown()

Discussion in 'Python' started by James Colannino, Nov 11, 2005.

  1. Hey everyone. I tried to use os.chown() in the following manner:

    os.chown('filename', 'username', 'groupname')

    I got an error, and when I googled for this function I realized that I
    must pass the numerical uid and gid. My question is, is there a way for
    me to change ownership based on the name instead of the number? Perhaps
    there's a function that will let me lookup the uid from the username,
    and the gid from the groupname?

    Thanks :)

    James

    --
    My blog: http://www.crazydrclaw.com/
    My homepage: http://james.colannino.org/

    "A well regulated militia being necessary to the security of a free
    state, THE RIGHT of the people to keep and bear arms SHALL NOT BE
    INFRINGED." --United States Constitution, Second Ammendment
     
    James Colannino, Nov 11, 2005
    #1
    1. Advertising

  2. James Colannino

    Mike Meyer Guest

    James Colannino <> writes:

    > Hey everyone. I tried to use os.chown() in the following manner:
    >
    > os.chown('filename', 'username', 'groupname')
    >
    > I got an error, and when I googled for this function I realized that I
    > must pass the numerical uid and gid. My question is, is there a way
    > for me to change ownership based on the name instead of the number?
    > Perhaps there's a function that will let me lookup the uid from the
    > username, and the gid from the groupname?


    You want pwd.getpwnam and grp.getgrnam.

    <mike
    --
    Mike Meyer <> http://www.mired.org/home/mwm/
    Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
     
    Mike Meyer, Nov 11, 2005
    #2
    1. Advertising

  3. Mike Meyer wrote:

    >You want pwd.getpwnam and grp.getgrnam.
    >
    >


    Thanks. Hope my newbie questions haven't gotten on anybody's nerves yet ;)

    James

    --
    My blog: http://www.crazydrclaw.com/
    My homepage: http://james.colannino.org/

    "A well regulated militia being necessary to the security of a free
    state, THE RIGHT of the people to keep and bear arms SHALL NOT BE
    INFRINGED." --United States Constitution, Second Ammendment
     
    James Colannino, Nov 11, 2005
    #3
  4. James Colannino

    Tim Roberts Guest

    James Colannino <> wrote:
    >
    >Hey everyone. I tried to use os.chown() in the following manner:
    >
    >os.chown('filename', 'username', 'groupname')
    >
    >I got an error, and when I googled for this function I realized that I
    >must pass the numerical uid and gid. My question is, is there a way for
    >me to change ownership based on the name instead of the number? Perhaps
    >there's a function that will let me lookup the uid from the username,
    >and the gid from the groupname?


    One way is:
    os.system( 'chown username:groupname filename')

    Are you doing this as root? The chown function is usually restricted to
    root.
    --
    - Tim Roberts,
    Providenza & Boekelheide, Inc.
     
    Tim Roberts, Nov 13, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. GfxGuy

    JNI/Linux/chown

    GfxGuy, May 28, 2005, in forum: Java
    Replies:
    6
    Views:
    2,531
    Ross Bamford
    May 29, 2005
  2. Carsten Haese

    Re: chown'ing by script

    Carsten Haese, Jan 6, 2010, in forum: Python
    Replies:
    4
    Views:
    302
    Steve Holden
    Jan 6, 2010
  3. Brian Candler
    Replies:
    2
    Views:
    344
    Emiel van de Laar
    Mar 2, 2005
  4. superfly2

    chown and file ownership

    superfly2, Jul 21, 2004, in forum: Perl Misc
    Replies:
    3
    Views:
    142
    J├╝rgen Exner
    Jul 22, 2004
  5. Tim O'Donovan

    chown recursively

    Tim O'Donovan, Jun 9, 2005, in forum: Perl Misc
    Replies:
    18
    Views:
    286
    Michael Zawrotny
    Jun 13, 2005
Loading...

Share This Page