[Top][All Lists]

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

Suggested enhancement to du command - show last modified date.

From: William Brendling
Subject: Suggested enhancement to du command - show last modified date.
Date: Fri, 3 Jun 2005 14:25:52 +0100

I use the "du" command to identify directories for potential
archiving. Candidate directories are those that are taking a lot of
space, and which are not currently being worked on. The "du" command
conveniently identified the first. To find out the latter requires
walking the directory tree, and performing a stat on each file (to
obtain the last modified date). "du" already does most of this.
Walking a large directory tree twice, once to collect the file sizes,
and a second time to collect the last modified date can be time
consuming. I therefore suggest that "du" should have an option to
collect the latest last modified date for the files in a directory.

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
560     2004/03/12.19:18        ./old/fileutils
256     2004/03/12.19:18        ./old/sh-utils
336     2004/03/12.19:18        ./old/textutils
1156    2004/03/12.19:18        ./old
14316   2005/06/02.13:53        ./po
636     2005/06/02.14:12        ./lib/.deps
6396    2005/06/02.14:12        ./lib
760     2005/06/02.14:13        ./src/.deps
19692   2005/06/02.18:47        ./src
1116    2005/06/02.13:53        ./doc
824     2005/06/02.13:53        ./man
52      2005/06/02.13:53        ./tests/basename
68      2005/06/02.13:53        ./tests/chgrp

I chose this default date format so that the "sort" utility will
regard it as one field, and so that alphabetical sorting is the same
as date sorting.

I can also specify the date format required, using the same syntax as
for the "date" command. For example, using "du
--last-modified=%e/%b/%Y" produces:

368     12/Mar/2004     ./config
1004     2/Jun/2005     ./m4
560     12/Mar/2004     ./old/fileutils
256     12/Mar/2004     ./old/sh-utils
336     12/Mar/2004     ./old/textutils
1156    12/Mar/2004     ./old
14316    2/Jun/2005     ./po
636      2/Jun/2005     ./lib/.deps
6396     2/Jun/2005     ./lib
760      2/Jun/2005     ./src/.deps
19692    2/Jun/2005     ./src
1116     2/Jun/2005     ./doc
824      2/Jun/2005     ./man
52       2/Jun/2005     ./tests/basename
68       2/Jun/2005     ./tests/chgrp

Without the "--last-modified" switch, the modified program functions
as previously.

If you think my suggestion worthwhile, I would be happy to contribute
my modified code back to the GNU project, but I am very much a GNU
newbie. I don't know how to generate patch files. Also I have not made
any attempt to update the man files or other documentation. Please let
me know if you would like me to submit the code, and if so, how I
should do so ?

Alternately, you could probably produce a better implementation, based
upon my description above.

Yours sincerely,

Bill Brendling.

reply via email to

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