#!/usr/bin/perl # fileusage listed according to users and time # usage example: fileusage.pl /home $files = join(' ',@ARGV); if (! open (DU,"du -sk $files|sort -nr |")) {die "Can't run du! $!\n";} printf "%8s %-8s %-16s %8s %8s %s\n", 'KBytes','Login','Name','Accessed',' Modified',' File'; while () { ($kb,$file) = split; ($dev,$ino,$mode,$nlink,$uid,$gid,$dev,$size,$atime,$mtime,$ctime)=stat($file); if ($uid != $previous_uid) { ($login,$pwd,$uid,$gid,$quota,$com,$name,$dir,$shell) = getpwuid($uid); ($name) = split(',',substr($name,0,20)); $previous_uid = $uid; } ($sec,$min,$hour,$md,$mon,$year) = localtime($mtime);$mm=$mon+1;$my=$year+1900; ($sec,$min,$hour,$ad,$mon,$year) = localtime($atime);$am=$mon+1;$ay=$year+1900; printf "%8s %-8s %-16s %04s-%02d-%02d %04s-%02d-%02d %s\n", $kb,$login,$name,$my,$am,$ad,$ay,$mm,$md,$file; }