From: Robert Klemme Date: 2012-02-08T07:20:08+09:00 Subject: Re: Make a file read-only? On Mon, Feb 6, 2012 at 9:14 PM, Jeremy Bopp wrote: > On 02/06/2012 01:38 PM, Intransition wrote: > More specifically, then, you want to remove the write permission from > the file, leaving it whatever other permissions were already set > (possibly none!).  In other words, you want to /mask out/ the write bits > from whatever the current file mode is.  Try the following: > > mode = 0100664 > mask = mode ^ 0222 > new_mode = mode & mask Interesting approach. I usually do it like this: irb(main):038:0> mode = 0100664 => 33204 irb(main):039:0> mask = 0222 => 146 irb(main):040:0> new_mode = (mode | mask) ^ mask => 33060 irb(main):041:0> "%07o" % new_mode => "0100444" Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/