How to find recently updated files
One of the problems with not using a synchronization tool to manage your FTP transfers (or Subversion, for that matter) is that it is very easy to lose track of which files need to be copied to the live server.
I often start working on a small bug in a web app, only to find that by the time I’ve fixed the issue there are dozens of files open—but which ones were actually changed and need releasing to live? Quite aside from the occasional config setting that is different, it’s inefficient to upload the entire app every time I make a few changes.
Thanks to Stuart Colville I now have a solution. Save this little Python script to your path (you might also need to chmod 755 it as well):
#!/usr/bin/python# -*- coding: utf-8 -*-# Created by Stuart Colville on 2008-02-13# Muffin Research Labs. http://muffinresearch.co.uk# lastmod: Print lastmodified since n hoursimport sys,os,timedef callback(arg, directory, files):for file in files:path = os.path.join(directory, file)lastmod = int(os.path.getmtime(path))if lastmod > int(time.time())-(arg*3600):print path.ljust(80), time.strftime("%d-%m-%Y %H:%M:%S",time.gmtime(lastmod))os.path.walk(".", callback, len(sys.argv) > 1 and int(sys.argv[1]) or 24)- Download this code: /code/lastmod.txt
Now just navigate to the directory where your app resides and run $ lastmod <em>hours</em>, where hours is the time period within which you want to see files that were modifed. The default period is 24 hours:
$ cd /Applications/MAMP/htdocs/taper$ lastmod 125./css 08-02-2008 13:42:06./images 08-02-2008 12:44:57./js 08-02-2008 13:53:07./css/taper.css 08-02-2008 13:42:06./images/taper.gif 08-02-2008 12:01:51./js/jquery.js 08-02-2008 13:53:07./system/cache 11-02-2008 11:03:44./system/logs 11-02-2008 11:03:44./system/application/controllers/taper.php 08-02-2008 15:50:52./system/application/libraries/Taper_db.php 08-02-2008 15:59:51./system/application/views/taper 08-02-2008 12:09:43./system/application/views/taper/breadcrumb.php 08-02-2008 12:45:05./system/application/views/taper/footer.php 08-02-2008 13:53:32./system/application/views/taper/header.php 08-02-2008 13:44:49./system/application/views/taper/table.php 08-02-2008 16:00:08./system/logs/log-2008-02-08.php 08-02-2008 16:00:51./system/logs/log-2008-02-11.php 11-02-2008 11:03:45
Voila! A list of all the files I need to remember to upload.
(I’d imagine that you need to specify the program to use to execute the program if you’re using this on Windows. And you’d probably have to install Python as well…)
Filed under: Technology.
Technorati tags: python
Bookmark this article with del.icio.us
Previously: February Refresh: Productivity
Next: Meet me at SXSW
Comments
- Matthew Pennell
- 88 days ago
Thanks, Adrian.
And one of these days, I’ll get round to using Subversion properly…
- #2
Or you could use the
findcommand.find <path_to_app> -mmin -60 -printwould show you everything modified in the past 60 minutes. Obviously change the 60 to suit the period you’re looking for.
One of these days I’ll get round to writing up how to use Ant with the FTP extension, which is how I used to upload my web app (before I got a VPS and so SSH access). It does the checking the times and uploading in one command.