Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use Stat::lsMode;
- $ARGC=@ARGV;
- $filename = ".";
- $helper=0;
- if ($ARGC>3){
- die "Too many parameters";
- }
- foreach $param (@ARGV) {
- $helper=1 if -d -e $param;
- if ($param eq "-l"){
- $lsShort=1;
- }elsif ($param eq "-L") {
- $lsLong=1;
- }elsif ($helper){
- $filename=$param;
- }
- }
- opendir($dh,$filename) || die "Can't open dir $filename: $!";
- @tab = readdir ($dh);
- @stab=sort(@tab);
- foreach $tb (@stab) {
- ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atmine,$mtime,$ctime,$blksize,$blocks) = stat("$filename"."/"."$tb");
- ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime($mtime);
- $uid =(stat $tb)[4];
- $name=(getpwuid $uid)[0];
- $years=$year+1900;
- $month=$mon+1;
- printf "%.30s ",$tb;
- print $name." ", if ($lsLong);
- print "\n" if (!$lsShort and !$lsLong);
- if ($lsShort or $lsLong){
- printf "%.10s ", $size;
- printf "%4d-%02d-%02d %02d:%02d:%02d ", $years,$month,$mday,$hour,$min,$sec;
- $type=-d $tb;
- if ($type) {
- print "d";
- }
- else {
- print "-";
- }
- $result = (stat($tb))[2];
- $permission=$mode & 07777;
- $permissions=format_perms($permission);
- print $permissions."\n";
- }
- }
- closedir $dh;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement