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

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Vikram S. (Guest)
on 2008-12-01 13:52
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
Tim H. (Guest)
on 2008-12-01 14:25
(Received via mailing list)
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
Vikram S. (Guest)
on 2008-12-01 14:29
Tim H. 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
This topic is locked and can not be replied to.