I Was so Impressed I Wrote More Code

I guess I was inspired by by Bradley Andersen's little perl mod 'ParseCron' do a little code writing in the same vain.

Like I mentioned in my last post there many aspects of sys-adm that boggle my little mind and on of the chief ones is how 'chmod' converts a slew of 3 digits into unix style file permissions.

I get the rwx or - part on the files system that is easy enough. It is how 756 does its majik that addles my brain. I know it is just a sum that add to 7 for full access and 0 for none but I never could remember much more than that. So I came up with this little mod (early days yet but might make it to CPAN in a few days)

It is called ParseCHMOD and you can find the first cut here not much to look at and just something I have thrown together in the lats half hour our so but a start.

So here is a sample run


use ParseCHMOD;

my $chmod= ParseCHMOD->new();

$chmod->parse_bits('561');
$chmod->parse_bits('511');
$chmod->parse_bits('777');
$chmod->parse_bits('001');

and when I run it I get


Owner can Read & Execute the file!
Group members can Read & Write the file!
Others can Only Execute the file!
and on the file system it looks like: r-xrw---x 

Owner can Read & Execute the file!
Group members can Only Execute the file!
Others can Only Execute the file!
and on the file system it looks like: r-x--x--x 

Owner can Read, Write & Execute the file!
Group members can Read, Write & Execute the file!
Others can Read, Write & Execute the file!
and on the file system it looks like: rwxrwxrwx 

Owner can do nothing to the file!
Group members can do nothing to the file!
Others can Only Execute the file!
and on the file system it looks like: --------x 

Heck there is most likely a perl one-liner that does the same thing that some smarty-pants has already thought out that one.

Well that is going to help me or at least let me figure out he correct permissions without bugging someone or going back again to the Wikipedia entry.

For me it works and maybe some other lost soul who is old enough to remember this guy

hqdefault.jpg

and can also laugh at this

C:\DOS
C:\DOS\RUN
RUN\DOS\RUN

1 Comment

What about the first bit? You know, the one that specifies setuid, setgid and the sticky bit?

http://en.wikipedia.org/wiki/Chmod

Leave a comment

About byterock

user-pic Long time Perl guy, a few CPAN mods allot of work on DBD::Oracle and a few YAPC presentations