line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#! perl |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
57628
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
4
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
61
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
package App::Dusage; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
dusage - provide disk usage statistics |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 SYNOPSIS |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
dusage [options] ctlfile |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
-a --allstats provide all statis |
17
|
|
|
|
|
|
|
-f --allfiles also report file statistics |
18
|
|
|
|
|
|
|
-g --gather gather new data |
19
|
|
|
|
|
|
|
-i input --data=input input data as obtained by 'du dir' |
20
|
|
|
|
|
|
|
or output with -g |
21
|
|
|
|
|
|
|
-p dir --dir=dir path to which files in the ctlfile are relative |
22
|
|
|
|
|
|
|
-r --retain do not discard entries which do not have data |
23
|
|
|
|
|
|
|
-u --update update the control file with new values |
24
|
|
|
|
|
|
|
-L resolve symlinks |
25
|
|
|
|
|
|
|
-h --help this help message |
26
|
|
|
|
|
|
|
--man show complete documentation |
27
|
|
|
|
|
|
|
--debug provide debugging info |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
ctlfile file which controls which dirs to report |
30
|
|
|
|
|
|
|
default is dir/.du.ctl |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head1 DESCRIPTION |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
Ever wondered why your free disk space gradually decreases? This |
35
|
|
|
|
|
|
|
program may provide you with some useful clues. |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
B is a Perl program which produces disk usage statistics. |
38
|
|
|
|
|
|
|
These statistics include the number of blocks that files or |
39
|
|
|
|
|
|
|
directories occupy, the increment since the previous run (which is |
40
|
|
|
|
|
|
|
assumed to be the day before if run daily), and the increment since 7 |
41
|
|
|
|
|
|
|
runs ago (which could be interpreted as a week, if run daily). |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
B is driven by a control file that describes the names of the |
44
|
|
|
|
|
|
|
files (directories) to be reported. It also contains the results of |
45
|
|
|
|
|
|
|
previous runs. |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
When B is run, it reads the control file, optionally gathers |
48
|
|
|
|
|
|
|
new disk usage values by calling the B program, prints the report, |
49
|
|
|
|
|
|
|
and optionally updates the control file with the new information. |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
Filenames in the control file may have wildcards. In this case, the |
52
|
|
|
|
|
|
|
wildcards are expanded, and all entries reported. Both the expanded |
53
|
|
|
|
|
|
|
names as the wildcard info are maintained in the control file. New |
54
|
|
|
|
|
|
|
files in these directories will automatically show up, deleted files |
55
|
|
|
|
|
|
|
will disappear when they have run out of data in the control file (but |
56
|
|
|
|
|
|
|
see the B<-r> option). |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
Wildcard expansion only adds filenames that are not already on the list. |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
The control file may also contain filenames preceded with an |
61
|
|
|
|
|
|
|
exclamation mark C; these entries are skipped. This is meaningful |
62
|
|
|
|
|
|
|
in conjunction with wildcards, to exclude entries which result from a |
63
|
|
|
|
|
|
|
wildcard expansion. |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
The control file may have lines starting with a dash C<-> that is |
66
|
|
|
|
|
|
|
I followed by a C, which will cause the report to start a |
67
|
|
|
|
|
|
|
new page here. Any text following the dash is placed in the page |
68
|
|
|
|
|
|
|
header, immediately following the text ``Disk usage statistics''. |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
The available command line options are: |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=over 4 |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=item B<-a> B<--allstats> |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
Reports the statistics for this and all previous runs, as opposed to |
77
|
|
|
|
|
|
|
the normal case, which is to generate the statistics for this run, and |
78
|
|
|
|
|
|
|
the differences between the previous and 7th previous run. |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=item B<-f> B<--allfiles> |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
Reports file statistics also. Default is to only report directories. |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=item B<-g> B<--gather> |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
Gathers new data by calling the B program. See also the C<-i> |
87
|
|
|
|
|
|
|
(B<--data>) option below. |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=item B<-i> I or <--data> I |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
With B<-g> (B<--gather>), write the obtained raw info (the output of the B program) to this file for subsequent use. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Without B<-g> (B<--gather>), a data file written in a previous run is reused. |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=item B<-p> I or B<--dir> I |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
All filenames in the control file are interpreted relative to this |
98
|
|
|
|
|
|
|
directory. |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=item B<-L> B<--follow> |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
Follow symbolic links. |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=item B<-r> B<--retain> |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
Normally, entries that do not have any data anymore are discarded. |
107
|
|
|
|
|
|
|
If this option is used, these entries will be retained in the control file. |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=item B<-u> B<--update> |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
Update the control file with new values. Only effective if B<-g> |
112
|
|
|
|
|
|
|
(B<--gather>) is also supplied. |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=item B<-h> B<--help> B<-?> |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
Provides a help message. No work is done. |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=item B<--man> |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Provides the complete documentation. No work is done. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=item B<--debug> |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
Turns on debugging, which yields lots of trace information. |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=back |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
The default name for the control file is |
129
|
|
|
|
|
|
|
I<.du.ctl>, optionally preceded by the name supplied with the |
130
|
|
|
|
|
|
|
B<-p> (B<--dir>) option. |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head1 EXAMPLES |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
Given the following control file: |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
- for manual pages |
137
|
|
|
|
|
|
|
maildir |
138
|
|
|
|
|
|
|
maildir/* |
139
|
|
|
|
|
|
|
!maildir/unimportant |
140
|
|
|
|
|
|
|
src |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
This will generate the following (example) report when running the |
143
|
|
|
|
|
|
|
command ``dusage -gu controlfile'': |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
Disk usage statistics for manual pages Wed Nov 23 22:15:14 2000 |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
blocks +day +week directory |
148
|
|
|
|
|
|
|
------- ------- ------- -------------------------------- |
149
|
|
|
|
|
|
|
6518 maildir |
150
|
|
|
|
|
|
|
2 maildir/dirent |
151
|
|
|
|
|
|
|
498 src |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
After updating the control file, it will contain: |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
- for manual pages |
156
|
|
|
|
|
|
|
maildir 6518:::::: |
157
|
|
|
|
|
|
|
maildir/dirent 2:::::: |
158
|
|
|
|
|
|
|
maildir/* |
159
|
|
|
|
|
|
|
!maildir/unimportant |
160
|
|
|
|
|
|
|
src 498:::::: |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
The names in the control file are separated by the values with a C; |
163
|
|
|
|
|
|
|
the values are separated by colons. Also, the entries found by |
164
|
|
|
|
|
|
|
expanding the wildcard are added. If the wildcard expansion had |
165
|
|
|
|
|
|
|
generated a name ``maildir/unimportant'' it would have been skipped. |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
When the program is rerun after one day, it could print the following |
168
|
|
|
|
|
|
|
report: |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
Disk usage statistics for manual pages Thu Nov 23 17:25:44 2000 |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
blocks +day +week directory |
173
|
|
|
|
|
|
|
------- ------- ------- -------------------------------- |
174
|
|
|
|
|
|
|
6524 +6 maildir |
175
|
|
|
|
|
|
|
2 0 maildir/dirent |
176
|
|
|
|
|
|
|
486 -12 src |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
The control file will contain: |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
- for manual pages |
181
|
|
|
|
|
|
|
maildir 6524:6518::::: |
182
|
|
|
|
|
|
|
maildir/dirent 2:2::::: |
183
|
|
|
|
|
|
|
maildir/* |
184
|
|
|
|
|
|
|
!maildir/unimportant |
185
|
|
|
|
|
|
|
src 486:498::::: |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
It takes very little fantasy to imagine what will happen on subsequent |
188
|
|
|
|
|
|
|
runs... |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
When the contents of the control file are to be changed, e.g. to add |
191
|
|
|
|
|
|
|
new filenames, a normal text editor can be used. Just add or remove |
192
|
|
|
|
|
|
|
lines, and they will be taken into account automatically. |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
When run without B<-g> (B<--gather>) option, it reproduces the report |
195
|
|
|
|
|
|
|
from the previous run. |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
When multiple runs are required, save the output of the B program |
198
|
|
|
|
|
|
|
in a file, and pass this file to B using the B<-i> (B<--data>) |
199
|
|
|
|
|
|
|
option. |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
Running the same control file with differing values of the B<-f> |
202
|
|
|
|
|
|
|
(B<--allfiles>) or B<-r> (B<--retain>) options may cause strange |
203
|
|
|
|
|
|
|
results. |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
=head1 CAVEATS |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
The program will screw up when you have filenames with newlines in |
208
|
|
|
|
|
|
|
them. This must be considered an early warning that there may be |
209
|
|
|
|
|
|
|
some serious troubles ahead. |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=head1 COMPATIBILITY NOTICE |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
This program is rewritten for Perl 5.005 and later. However, it is |
214
|
|
|
|
|
|
|
still fully backward compatible with its 1990 predecessor. |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
=head1 AUTHOR |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
Johan Vromans, C<< >> |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
=head1 SUPPORT AND DOCUMENTATION |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
Development of this module takes place on GitHub: |
223
|
|
|
|
|
|
|
https://github.com/sciurius/perl-App-Dusage. |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
perldoc App::Dusage |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
Please report any bugs or feature requests using the issue tracker on |
230
|
|
|
|
|
|
|
GitHub. |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
=head1 LICENSE |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
Copyright (C) 1990, 2000, 2021, Johan Vromans |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
This module is free software. You can redistribute it and/or |
237
|
|
|
|
|
|
|
modify it under the terms of the Artistic License 2.0. |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful, |
240
|
|
|
|
|
|
|
but without any warranty; without even the implied warranty of |
241
|
|
|
|
|
|
|
merchantability or fitness for a particular purpose. |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
=cut |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
1; |