# File permissions w/Dir.mkdir

**URL:** <https://www.ruby-forum.com/t/file-permissions-w-dir-mkdir/107985>\
**Category:** Ruby\
**Created:** [June 28, 2007, 4:25am UTC](https://www.ruby-forum.com/t/file-permissions-w-dir-mkdir/107985 "2007-06-28T04:25:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![john\_old](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9f8e36/32.png) [@john\_old](https://www.ruby-forum.com/u/john_old)\
**Post date:** [June 28, 2007, 4:25am UTC](https://www.ruby-forum.com/t/file-permissions-w-dir-mkdir/107985/1 "2007-06-28T04:25:22Z")

</div>

In OS X 10.4.9, Ruby 1.8.4 when I use:  
Dir.mkdir(file\_name, 755)

The directories created are drop-box, owner-only.  
It seems the Dir class expects the leading bit.  
So, it should be 0755 and not 755.

When using:  
Dir.mkdir(file\_name)

Without permissions, it appears to default to 0755.

Just thought this might be useful for some people.  
Seems like I read this in the Pickaxe, but I forgot.  
It is interesting, since chmod accepts 755 and assumes you mean 0755  
Seems to me that Dir should do the same assuming… but doesn’t

John J.

---

<div class="post-metadata">

**Author:** ![john\_old](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9f8e36/32.png) [@john\_old](https://www.ruby-forum.com/u/john_old)\
**Post date:** [June 28, 2007, 4:45am UTC](https://www.ruby-forum.com/t/file-permissions-w-dir-mkdir/107985/2 "2007-06-28T04:45:23Z")

</div>

On Thu, Jun 28, 2007 at 11:24:14AM +0900, John J. wrote:

> Without permissions, it appears to default to 0755.
> 
> Just thought this might be useful for some people.  
> Seems like I read this in the Pickaxe, but I forgot.  
> It is interesting, since chmod accepts 755 and assumes you mean 0755  
> Seems to me that Dir should do the same assuming… but doesn’t

Dir.mkdir accepts octal numbers, which is standard notation for this  
sort of thing. A leading 0 makes Ruby interpret it as octal. You _could_  
say Dir.mkdir(file\_name, 493), but that’s sick and twisted.

Also, without the second argument it defaults to 0777, which will get  
modified by the umask. cf lines 912-917 of dir.c in the ruby 1.8.6  
source.

The reason chmod on the command line accepts 755 is because it can  
assume you mean octal digits. Also, I think I’ve come across a few  
(weirder) chmods that require the leading 0, but that was a long time  
ago.
