Advertisement
Guest User

Untitled

a guest
Mar 24th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. #!/usr/bin/perl
  2. use Stat::lsMode;
  3. $ARGC=@ARGV;
  4. $filename = ".";
  5. $helper=0;
  6. if ($ARGC>3){
  7. die "Too many parameters";
  8. }
  9.  
  10. foreach $param (@ARGV) {
  11. $helper=1 if -d -e $param;
  12. if ($param eq "-l"){
  13. $lsShort=1;
  14. }elsif ($param eq "-L") {
  15. $lsLong=1;
  16. }elsif ($helper){
  17. $filename=$param;
  18. }
  19.  
  20. }
  21.  
  22. opendir($dh,$filename) || die "Can't open dir $filename: $!";
  23. @tab = readdir ($dh);
  24. @stab=sort(@tab);
  25. foreach $tb (@stab) {
  26. ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atmine,$mtime,$ctime,$blksize,$blocks) = stat("$filename"."/"."$tb");
  27. ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime($mtime);
  28. $uid =(stat $tb)[4];
  29. $name=(getpwuid $uid)[0];
  30. $years=$year+1900;
  31. $month=$mon+1;
  32. printf "%.30s ",$tb;
  33. print $name." ", if ($lsLong);
  34. print "\n" if (!$lsShort and !$lsLong);
  35. if ($lsShort or $lsLong){
  36. printf "%.10s ", $size;
  37. printf "%4d-%02d-%02d %02d:%02d:%02d ", $years,$month,$mday,$hour,$min,$sec;
  38. $type=-d $tb;
  39. if ($type) {
  40. print "d";
  41. }
  42. else {
  43. print "-";
  44. }
  45. $result = (stat($tb))[2];
  46. $permission=$mode & 07777;
  47. $permissions=format_perms($permission);
  48. print $permissions."\n";
  49. }
  50. }
  51. closedir $dh;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement