bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Suggested enhancement to du command - show last modified date.


From: James Youngman
Subject: Re: Suggested enhancement to du command - show last modified date.
Date: Fri, 3 Jun 2005 17:18:39 +0100
User-agent: Mutt/1.3.28i

On Fri, Jun 03, 2005 at 02:25:52PM +0100, William Brendling wrote:

> I have hacked together a version of "du" that does this, taking the
> date formatting code from the "date" utility. If my modified program
> is run as (for example) "du --last-modified", it produces output such
> as the following:
> 
> 368   2004/03/12.19:18        ./config
> 1004  2005/06/02.13:53        ./m4

You could have done the same thing with GNU "find" without modifying it:-


$ find . -depth -printf "%-10k %TY/%Tm/%Td.%TH:%TM:%TS %p\n" | perl 
/tmp/totify.pl
48         2004/04/03.19:38:39 ./cv/JY-external-CV-2004-03-31.rtf
44         2004/01/20.11:01:44 ./cv/jy.rtf
92         2004/04/03.19:38:39 ./cv
4          2004/03/06.12:40:16 
./ukuug/book-reviews/Computer_Science_and_Perl_Programming.txt
4          2004/01/25.13:33:16 
./ukuug/book-reviews/Postfix_The_Definitive_Guide.txt
8          2004/03/06.12:40:16 ./ukuug/book-reviews
8          2004/02/28.18:53:51 ./ukuug/opening-the-jvm.txt
8          2004/04/16.13:44:30 ./ukuug/L2004-draft-budget.txt
20         2004/08/08.11:17:38 ./ukuug
4          2004/04/03.22:21:19 ./jab-domain.txt
72         2004/01/13.18:53:08 ./old-cv/JY-external-CV-2004-01-02.doc
44         2004/01/20.11:01:44 ./old-cv/JY-external-CV-2004-01-02.rtf
116        2004/01/20.11:01:44 ./old-cv
20         2005/06/03.17:05:27 .


The totify.pl script would be :-

#! /usr/bin/perl -w
use File::Basename qw(dirname);

my %totsize;
my %latest;

while (<>) {
    my ($size, $time, $path) = split;
    my $parent = dirname($path);
    $totsize{$parent} += $size;

    # Assume the time field is zero-padded in such a way
    # that lexicographic ordering is the same as string comparison
    # ordering.
    if (!defined($latest{$parent}) || ($time gt $latest{$parent})) {
        $latest{$parent} = $time;
    }

    if (defined($totsize{$path})) {
        # So, $path must be a directory (we assume that the input
        # is the result of a depth-first search).
        printf("%-10d %s %s\n", $totsize{$path}, $latest{$path}, $path);

        # XXX: optional: $totsize{dirname($parent)} += $totsize{$path}
        #  -- and similarly with the last modified time.
    } else {
        print;
    }
}



Regards,
James Youngman.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]