Commits

Anonymous committed 3251ec1

Added the analyse-du.pl file.

Comments (0)

Files changed (1)

du-output-analyser/analyse-du.pl

+#!/usr/bin/perl
+
+# Copyright (c) 2008, Shlomi Fish
+# 
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+# 
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+# 
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+# THE SOFTWARE.
+
+use strict;
+use warnings;
+
+use Getopt::Long;
+
+my $prefix = "";
+my $depth = 1;
+my $sort = 1;
+
+GetOptions(
+    "prefix|p=s" => \$prefix,
+    "depth|d=n" => \$depth,
+    "sort" => \$sort,
+);
+my @results=();
+while(my $line = <>)
+{
+    chomp($line);
+    if ($line =~ /^(\d+)\t.\/(.*)$/)
+    {
+        my ($size, $path) = ($1, $2);
+        if (
+                (substr($path, 0, length($prefix)) eq $prefix)
+                    &&
+                ((substr($path, length($prefix)) =~ tr{/}{/}) == $depth)
+           )
+        {
+            push @results, [$path, $size];
+        }
+    }
+}
+if ($sort)
+{
+    @results = (sort { $a->[1] <=> $b->[1] } @results);
+}
+print map { "$_->[1]\t$_->[0]\n" } @results;
+
+=head1 NAME
+
+analyse-du.pl - analyse the output of C<\du .>
+
+=head1 SYNPOSIS
+
+B<analyse-du.pl> --prefix=progs/ --depth=1 --sort
+
+=head1 DESCRIPTION
+
+This analyses the output of C<\du .> looking for directories with a certain
+prefix, a certain depth and possibly sorting the output by size. It aims to
+aid in finding the most space-consuming components in the directory tree
+on the disk.
+
+=head1 OPTIONS
+
+=over 4
+
+=item B<--prefix> | B<-p>
+
+This specifies a prefix for the directories according which to filter them. 
+
+=item B<--depth> | B<-d>
+
+This specifies a depth of the directories and their component numbers.
+
+Defaults to 1.
+
+=item B<--nosort>
+
+When specified, this option instructs not to sort the items according to their
+size.
+
+=back
+
+=head1 CREDITS
+
+Written by Shlomi Fish - L<http://www.shlomifish.org/> .
+
+=head1 COPYRIGHTS & LICENSE
+
+Copyright by Shlomi Fish, 2008. All rights reserved.
+
+This file is licensed under the MIT X11 License:
+
+L<http://www.opensource.org/licenses/mit-license.php>
+
+=cut
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.