Well, heck. One of our Great and Holy Brethren, jdporter, took a shot at rewriting 'cut'... I can be brave too. :) Well, not all _that_ brave - I'm not rewriting "ls" from scratch, thankyouverymuch - but I've always wondered why it doesn't have an option for displaying permissions in octal. Well, now it does.
I've kept the formatting and all the other goodies of "ls" - you can still specify all the same options, etc. (not that I've done a huge amount of testing; I'm sure there are edge cases that would break it - I just haven't managed to come up with any.) I also suspect that there are better, smarter ways to do this, so comments would be very welcome.
Anyway, here it is. Enjoy.
#!/usr/bin/perl -w # Created by Ben Okopnik on Sat Mar 26 19:00:46 EDT 2011 use strict; for my $ls (qx#/bin/ls -l @ARGV#){ my ($t, $p, $r) = $ls =~ /^(.)([rwxsStT-]+)(\s+\d+\s+\w+.+)$/; print $ls and next unless $p; my $out = 0; my %d = map {split//} qw/sx S- r4 w2 x1 -0/; $out += 01000 if $p =~ y/tT/x-/; $out += 02000 if $p =~ s/(s)(?=.{3})$/$d{$1}/i; $out += 04000 if $p =~ s/(s)(?=.{6})$/$d{$1}/i; for ((100) x 3, (10) x 3, (1) x 3){ $out += $d{$1} * oct($_) if $p =~ s/([rwx-])//; } printf "[%s] %04o %s\n", $t, $out, $r; }
-- Education is not the filling of a pail, but the lighting of a fire. -- W. B. Yeats
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: 'ls' with octal permissions
by jwkrahn (Abbot) on Mar 27, 2011 at 03:43 UTC | |
by oko1 (Deacon) on Mar 27, 2011 at 14:35 UTC | |
|
Re: 'ls' with octal permissions
by owill (Initiate) on Jun 06, 2012 at 14:46 UTC |