# File.stat.mode not same mode as File.stat.inspect?

**URL:** <https://www.ruby-forum.com/t/file-stat-mode-not-same-mode-as-file-stat-inspect/61632>\
**Category:** Ruby\
**Created:** [May 25, 2006, 7:37pm UTC](https://www.ruby-forum.com/t/file-stat-mode-not-same-mode-as-file-stat-inspect/61632 "2006-05-25T19:37:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![zbrod](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/278dde/32.png) [@zbrod](https://www.ruby-forum.com/u/zbrod)\
**Post date:** [May 25, 2006, 7:37pm UTC](https://www.ruby-forum.com/t/file-stat-mode-not-same-mode-as-file-stat-inspect/61632/1 "2006-05-25T19:37:41Z")

</div>

I am working on a little ruby script to check file stats and I am  
getting a weird mask when I query the mode directly. I am also looking  
at stat.2 (man 2 stat) and the bits just are not adding up to give me 8.

The proper mode is 0100644 but when I print @mode = fileObj.stat.mode I  
get 33188

## print “-----\n”, fileObj.stat.inspect, “\n-----\n”

## #\<File::Stat dev=0x6809, ino=19, mode=0100644, nlink=1, uid=506, gid=501, rdev=0x0, size=50, blksize=4096, blocks=8, atime=Tue May 23 16:19:47 MST 2006, mtime=Tue May 23 16:19:47 MST 2006, ctime=Tue May 23 16:19:47 MST 2006\>

print fileObj.stat.mode  
33188 \<---- Value that’s confusing me  
print fileObj.stat.uid  
501  
print fileObj.stat.gid  
506

Can anyone clarify what I am doing wrong?

Thanks  
Zach

---

<div class="post-metadata">

**Author:** ![zbrod](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/278dde/32.png) [@zbrod](https://www.ruby-forum.com/u/zbrod)\
**Post date:** [May 25, 2006, 7:45pm UTC](https://www.ruby-forum.com/t/file-stat-mode-not-same-mode-as-file-stat-inspect/61632/2 "2006-05-25T19:45:59Z")

</div>

Zach B. wrote:

> I am working on a little ruby script to check file stats and I am  
> getting a weird mask when I query the mode directly. I am also looking  
> at stat.2 (man 2 stat) and the bits just are not adding up to give me 8.
> 
> The proper mode is 0100644 but when I print @mode = fileObj.stat.mode I  
> get 33188

0100644 octal == 33188 decimal

---

<div class="post-metadata">

**Author:** ![zbrod](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/278dde/32.png) [@zbrod](https://www.ruby-forum.com/u/zbrod)\
**Post date:** [May 25, 2006, 7:50pm UTC](https://www.ruby-forum.com/t/file-stat-mode-not-same-mode-as-file-stat-inspect/61632/3 "2006-05-25T19:50:38Z")

</div>

On 5/25/06, Zach B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I am working on a little ruby script to check file stats and I am  
> getting a weird mask when I query the mode directly. I am also looking  
> at stat.2 (man 2 stat) and the bits just are not adding up to give me 8.
> 
> The proper mode is 0100644 but when I print @mode = fileObj.stat.mode I  
> get 33188

You are displaying the mode in decimal when it should be octal to  
match what you think it should be:

irb(main):001:0\> ‘%07o’ % 33188  
=\> "0100644

Ryan
