Scanning for specific UNIX permissions

Author: Samuel Williams When: Thursday, 17 September 2009

This script will scan for a specific mask on directories and print out the result:

#!/usr/bin/env ruby
 
require 'find'
require 'etc'
 
# http://permissions-calculator.org/
MASK = 0002
 
Find.find(ARGV[0] || "./") do |path|
	if FileTest.directory?(path)
		s = File::Stat.new(path)
		if (s.mode & MASK) != 0
			puts "#{s.mode.to_s(8)} #{Etc.getpwuid(s.uid).name} #{Etc.getgrgid(s.gid).name}: #{path}"
		end
	end
end

Comments

There are currently no comments.
Your Icon:
[City], [Country]
Publicly displayed.
Your email won't be displayed.
The following tags are preserved: <pre>, <em> and <a>. All comments are moderated.

Please note, you can leave a comment that uses (limited) XHTML and Textile syntax.