Leser: 2
![]() |
|< 1 2 3 4 5 >| | ![]() |
44 Einträge, 5 Seiten |
Quote
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/usr/bin/perl
use strict;
use warnings;
use vars qw(%files);
opendir(DIR, '.') or die $!;
$files{$_} = -s for grep -e && -f, readdir( DIR );
closedir(DIR);
printf("%s\t%s\n", human_readable_fsize($files{$_}), $_ )
for sort { $files{$a} <=> $files{$b} } keys %files;
sub human_readable_fsize {
my(@units) = qw(Bytes KB MB GB TB);
my $i = $_[0] >= 1099511627776 # 1024 ** 4
? 4 : $_[0] >= 1073741824 # 1024 ** 3
? 3 : $_[0] >= 1048576 # 1024 ** 2
? 2 : $_[0] >= 1024
? 1 : 0;
return sprintf('%.2f %s', $_[0] / 1024 ** $i, $units[$i]);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/perl
use strict;
use warnings;
use Cwd;
my $dir = getcwd;
opendir(DIR, "$dir");
my @array = readdir(DIR);
closedir(DIR);
my %hash;
my %for;
my @size;
my $data;
format STDOUT_TOP =
Dateiname Dateigroesse
====================================
.
foreach(@array)
{
my $i = 0;
$hash{$_} = (-s $_);
my $file = (-s $_);
$for{$file} = $_;
$i++;
push @size, $file;
}
my @sort = sort { $a <=> $b } @size;
foreach(@sort)
{
if (-f, "$for{$_}" && !(-d "$for{$_}"))
{
my $data = $_;
if ($_ < 1024)
{
$_ .= " bytes";
} elsif ( $_ > 1024 && $_ < 1048576)
{
$_ = sprintf("%.2f", $_ / 1024);
$_ .= " kb";
} elsif ( $_ > 1048576 && $_ < 1099511627776)
{
$_ = sprintf("%.2f", $_ / 1048576);
$_ .= " mb";
} else
{
$_ = sprintf("%.2f", $_ / 1099511627776);
$_ .= " gb";
}
format STDOUT =
@<<<<<<<<<<<<<<<<< @>>>>>>>>>>>>>>
$for{$data}, $_
.
write;
}
}
$hash{$_} = (-s $_);
push @size, $file;
$i++;
my @sort = sort { $a <=> $b } @size;
my @sort = sort { $hash{$a} <=> $hash{$b} } keys %hash;
my @sort = sort { $hash{$a} <=> $hash{$b} } keys %hash;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
my @sort = sort { $a <=> $b } @size;
foreach(@sort)
{
if (-f, "$for{$_}" && !(-d "$for{$_}"))
{
my $data = $_;
if ($_ < 1024)
{
$_ .= " bytes";
} elsif ( $_ > 1024 && $_ < 1048576)
{
$_ = sprintf("%.2f", $_ / 1024);
$_ .= " kb";
} elsif ( $_ > 1048576 && $_ < 1099511627776)
{
$_ = sprintf("%.2f", $_ / 1048576);
$_ .= " mb";
} else
{
$_ = sprintf("%.2f", $_ / 1099511627776);
$_ .= " gb";
}
format STDOUT =
@<<<<<<<<<<<<<<<<< @>>>>>>>>>>>>>>
$for{$data}, $_
.
write;
}
1
2
3
4
5
6
7
8
9
10
foreach my $filename ( sort { $hash{$a} <=> $hash{$b} } keys %hash )
{
next unless -f $filename;
format STDOUT =
@<<<<<<<<<<<<<<<<< @>>>>>>>>>>>>>>
human_readable_fsize( $hash{$filename} ), $filename
.
write;
}
if (-f, "$for{$_}" && !(-d "$for{$_}"))
QuoteAber wenn ich ihn mir so anschaue, muss ich mir doch noch einige Bücher kaufen *gg*
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/usr/bin/perl
use strict;
use warnings;
use Cwd;
use Getopt::Std;
use vars qw($opt_f $opt_h $opt_d);
my $test=0;
my $name;
my $wert;
my $dir;
if (! getopts('f:hd:'))
{
}
if ($opt_h)
{
print "Usage:\n";
print "filesize.pl -h for help\n";
print "filesize.pl -f [filename] to show the size of [filename]\n";
print "filesize.pl -d [directory] to show the sizes of all files in [directory]\n";
print "filesize.pl to show the sizes of all files in the current directory\n";
}
elsif ($opt_f)
{
my $f = getcwd;
opendir(DIR, "$f");
my @dir = readdir(DIR);
closedir(DIR);
foreach (@dir)
{
if ($_ eq $opt_f)
{
$test=1;
}
}
if ($test)
{
$_ = (-s "$opt_f");
$wert = &size($_);;
$name = $opt_f;
write;
}
else {
print "Datei $opt_f exisiert nicht!\n";
}
}
$dir = getcwd unless(defined($opt_d));
if (defined($opt_d))
{
if (-d "$opt_d")
{
$dir = $opt_d;
} else {
print "$opt_d existiert nicht oder ist kein Verzeichniss!\n";
exit 0;
}
}
unless (defined($opt_h) || defined($opt_f))
{
opendir(DIR, "$dir");
my @array = readdir(DIR);
closedir(DIR);
my %hash;
my %for;
my @size;
format STDOUT_TOP =
Dateiname Dateigroesse
====================================
.
foreach(@array)
{
my $i = 0;
$hash{$_} = (-s $_);
my $file = (-s $_);
$for{$file} = $_;
$i++;
push @size, $file;
}
my @sort = sort { $a <=> $b } @size;
foreach(@sort)
{
if (-f "$for{$_}")
{
my $data = $_;
&size($_);
$name = $for{$data};
$wert = $_;
format STDOUT =
@<<<<<<<<<<<<<<<<< @>>>>>>>>>>>>>>
$name, $wert
.
write;
}
}
}
sub size
{
if ($_ < 1024)
{
$_ .= " bytes";
} elsif ( $_ > 1024 && $_ < 1048576)
{
$_ = sprintf("%.2f", $_ / 1024);
$_ .= " kb";
} elsif ( $_ > 1048576 && $_ < 1099511627776)
{
$_ = sprintf("%.2f", $_ / 1048576);
$_ .= " mb";
} else
{
$_ = sprintf("%.2f", $_ / 1099511627776);
$_ .= " gb";
}
return $_;
}
1
2
3
4
5
rootcris@ingo:~/scripts$ ./filesize.pl -d /home/rootcris/filme/
Use of uninitialized value in hash element at ./filesize.pl line 84.
Use of uninitialized value in sort at ./filesize.pl line 88.
Use of uninitialized value in sort at ./filesize.pl line 88.
Use of uninitialized value in hash element at ./filesize.pl line 93.
![]() |
|< 1 2 3 4 5 >| | ![]() |
44 Einträge, 5 Seiten |