-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathduh
More file actions
executable file
·22 lines (22 loc) · 962 Bytes
/
duh
File metadata and controls
executable file
·22 lines (22 loc) · 962 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/usr/bin/perl
use strict;
my $usage = q/Usage:
duh [<directories..>]
Shows du (disk usage) sorted by decreasing size, with
human-readable suffixes (G,M)
If no arguments are given the size of all files and directories
within the current directory is considered.
/;
umask 0002;
die($usage."\n") if $ARGV[0]=~m/^\-+h/;
my $cmd=(@ARGV==1) ? 'du --apparent-size -shx ' : 'du --apparent-size -schx ';
my $q = @ARGV>0; #user provided target
#$cmd.= $q ? join(' ',@ARGV) : '* .[^.]*';
$cmd .= $q ? join(' ', @ARGV) : '* .[!.]* ..?*';
open(DU, "-|", "$cmd 2>/dev/null") || die("Error starting $cmd | pipe!\n");
# Schwartzian transform
my %byte_order=(K => 0, M => 1, G => 2, T => 3);
print map { $_->[0]=~m/^[\d\.]*K?\s+/ && !$q ? '' : $_->[0]=~s/^(\S+)\s+total/( $1 total )/ ? $_->[0] : $_->[0] }
sort { $byte_order{$main::a->[1]} <=> $byte_order{$main::b->[1]} || $main::a->[2] <=> $main::b->[2] }
map { [ $_, /([MGKT])/, /(\d+)/ ] } <DU> ;
close(DU);