How to find recently updated files

Feb 13 2008

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):

  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3.  
  4. # Created by Stuart Colville on 2008-02-13
  5. # Muffin Research Labs. http://muffinresearch.co.uk
  6. # lastmod: Print lastmodified since n hours
  7.  
  8. import sys,os,time
  9.  
  10. def callback(arg, directory, files):
  11. for file in files:
  12. path = os.path.join(directory, file)
  13. lastmod = int(os.path.getmtime(path))
  14. if lastmod > int(time.time())-(arg*3600):
  15. print path.ljust(80), time.strftime("%d-%m-%Y %H:%M:%S",time.gmtime(lastmod))
  16. os.path.walk(".", callback, len(sys.argv) > 1 and int(sys.argv[1]) or 24)
  17. 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:

  1. $ cd /Applications/MAMP/htdocs/taper
  2. $ lastmod 125
  3.  
  4. ./css 08-02-2008 13:42:06
  5. ./images 08-02-2008 12:44:57
  6. ./js 08-02-2008 13:53:07
  7. ./css/taper.css 08-02-2008 13:42:06
  8. ./images/taper.gif 08-02-2008 12:01:51
  9. ./js/jquery.js 08-02-2008 13:53:07
  10. ./system/cache 11-02-2008 11:03:44
  11. ./system/logs 11-02-2008 11:03:44
  12. ./system/application/controllers/taper.php 08-02-2008 15:50:52
  13. ./system/application/libraries/Taper_db.php 08-02-2008 15:59:51
  14. ./system/application/views/taper 08-02-2008 12:09:43
  15. ./system/application/views/taper/breadcrumb.php 08-02-2008 12:45:05
  16. ./system/application/views/taper/footer.php 08-02-2008 13:53:32
  17. ./system/application/views/taper/header.php 08-02-2008 13:44:49
  18. ./system/application/views/taper/table.php 08-02-2008 16:00:08
  19. ./system/logs/log-2008-02-08.php 08-02-2008 16:00:51
  20. ./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:

Digg this article

Bookmark this article with del.icio.us

Previously: February Refresh: Productivity

Next: Meet me at SXSW


Comments

Adrian McEwen
89 days ago

Or you could use the find command.
find <path_to_app> -mmin -60 -print
would 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.

#1
Matthew Pennell
88 days ago

Thanks, Adrian.

And one of these days, I’ll get round to using Subversion properly…

#2