Wednesday, October 10, 2012

Listing files in a hierarchy, ordered by size, mtime etc ..

Nowadays I put all my eBooks into my Dropbox.  I've got more than a thousand PDFs in there and am frequently adding new ones.  Of course I don't have time to read them but I would like to be able to see which are the latest additions in the hierarchy of files.

I was surprised not to find a utility to do this for me ... I'm sure I'm reinventing the wheel and would have preferred to pick up an existing script.  But I didn't find one so I set about hacking a quick Perl script. So far Perl is what's quickest and easiest for me.

The script usage is show below:

Usage:
  ./findFiles.pl [-r] [-] [-size|-mtime|-ctime|-atime] <DIR>

   -size:   order by file/dir size
   -mtime:  order by file/dir mtime
   -ctime:  order by file/dir ctime
   -atime:  order by file/dir atime

   -f: only list files
   -d: only list directories
   -r: reverse 'descending' order of listing
   -: show only N elements

So now to see which files were added last into my z/Books hierarchy I run the command
    ./findFiles.pl -mtime z/Books/

or to see just the 10 oldest
    ./findFiles.pl -r -10 -mtime z/Books/

or the 10 largest
    ./findFiles.pl -r -10 -mtime z/Books/

The script is available here in my github Tools repository.




That wasn't the plan ... I was going to do some Python/Django or some C# this evening ...




No comments:

[Conference - CodeEurope.pl] Developing Micro-services on Kubernetes

In April I had the chance to present at CodeEurope.pl , first in Warsaw on Apr 24th, and then in Wroclaw ("wroslof" was my best at...