List files recursively by modified time
22 May 2008
Often when using my computer, I will have a "project", by this I mean a directory containing an arbitrary number of files and directories. This could be a software project, or a website, or an essay, or whatever.
So when going back to a project, I might want a quick overview of what has been going on. This is what my filehistory.py script is for. It recursively orders your project files by last modified date.
The unique feature is that it mixes them all together as one stream. There is of course a tradeoff, the larger the number of files, the longer it takes, however it is quite fine for projects of up to several thousand files.
There are a few command line arguments:
- By default, the output is just the filepaths, if you use -v then it outputs timestamps as well.
- By default, it will output warnings if it finds permission errors or malformed symlinks in your project. If you want to suppress these messages, use -q.
- By default, it will output all the files within your project. If you want to specify the number of lines then use -n followed by the number. So -n 20 will output the most recently edited files.
If you followed my post about making a scripts-directory, then you can just make the Python file executable and drop the Python file into it.
It really comes into its own when you pipe it to other tools. For example, to copy the last 20 modified files to a USB stick mounted at /media/disk :
filehistory.py -q -n 20 | xargs -I x cp x /media/disk/
So feel free to check out my filehistory script. As you know I use Linux, but I think this particular script should work on Windows/Mac as well.




1 David Jones says...
"-n 20" is a sin against Unix; should be using head or tail. See also "cat -v" etc, etc.
Posted at 9:22 p.m. on September 8, 2008