Created
May 29, 2015 14:43
-
-
Save spiculator/4b901fa909934eeaf97f to your computer and use it in GitHub Desktop.
List all open files sorted by size, including deleted files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl -w | |
use strict; | |
use Number::Bytes::Human qw/format_bytes/; | |
my $count = 30; | |
if( @ARGV ) { | |
die "Usage: $0 <count>\n" if @ARGV > 1; | |
$count = shift @ARGV; | |
die "bad count\n" unless $count =~ /^\d+/; | |
} | |
my (@names, @sizes); | |
foreach (</proc/*/fd/*>) { | |
my @s = stat($_); | |
next unless @s; | |
my $size = $s[7]; | |
die unless defined $size; | |
push @names, $_; | |
push @sizes, $size; | |
} | |
my %skip; | |
for( sort { $sizes[$b] <=> $sizes[$a] } (0 .. $#sizes) ) { | |
my $realname = readlink $names[$_]; | |
if(defined $realname) { | |
next if $skip{$realname}; | |
$skip{$realname} = 1; | |
} else { | |
$realname = "(cannot read link)"; | |
} | |
printf "%s:\t%s\t%s\n", format_bytes($sizes[$_]), $names[$_], $realname; | |
last if --$count <= 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment