Using File:Stat.mode method to find file permissions in Unix

Discussion in 'Ruby' started by Vikram Sharma, Dec 1, 2008.

  1. Hi,

    I am trying to find the permissions on a file, using mode method of
    File:Stat.

    Code :

    s = File.stat(file_name)
    p s.mode

    For a file having 777 permissions, this prints : 16895

    Any Idea on what does this number imply ?

    Thanks,
    Vikram
    --
    Posted via http://www.ruby-forum.com/.
    Vikram Sharma, Dec 1, 2008
    #1
    1. Advertising

  2. Vikram Sharma

    Tim Hunter Guest

    Vikram Sharma wrote:
    > Hi,
    >
    > I am trying to find the permissions on a file, using mode method of
    > File:Stat.
    >
    > Code :
    >
    > s = File.stat(file_name)
    > p s.mode
    >
    > For a file having 777 permissions, this prints : 16895
    >
    > Any Idea on what does this number imply ?
    >
    > Thanks,
    > Vikram


    Permissions are typically specified as octal numbers. 16895 is decimal.

    "%o" % 16895 # -> 40777

    --
    RMagick: http://rmagick.rubyforge.org/
    Tim Hunter, Dec 1, 2008
    #2
    1. Advertising

  3. Tim Hunter wrote:
    > Vikram Sharma wrote:
    >> For a file having 777 permissions, this prints : 16895
    >>
    >> Any Idea on what does this number imply ?
    >>
    >> Thanks,
    >> Vikram

    >
    > Permissions are typically specified as octal numbers. 16895 is decimal.
    >
    > "%o" % 16895 # -> 40777


    Oh Yes ! Thanks a lot.. :)

    Cheers,
    Vikram
    --
    Posted via http://www.ruby-forum.com/.
    Vikram Sharma, Dec 1, 2008
    #3
    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. Steven T. Hatton
    Replies:
    3
    Views:
    9,703
    Pete Becker
    Jun 2, 2005
  2. Patrick Useldinger

    os.stat('<filename>')[stat.ST_INO] on Windows

    Patrick Useldinger, Feb 27, 2005, in forum: Python
    Replies:
    6
    Views:
    1,166
    =?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=
    Mar 3, 2005
  3. Magesh
    Replies:
    3
    Views:
    441
    Gordon Burditt
    Oct 5, 2007
  4. Rolf Krüger
    Replies:
    2
    Views:
    612
    Ian Collins
    Mar 12, 2008
  5. ruck
    Replies:
    10
    Views:
    1,272
Loading...

Share This Page