Compare Symlink and Target Modified Dates (script)

Here’s a short script that will check a specific directory for symbolic links and then:

  1. check the modification date of symlinks’ respective targets
  2. if the modification date of a symlink is older than the modification date of it’s target, the symlink is “touched” updating it’s modification date

That’s it. I created this to help make a file syncing service operate slightly differently than designed. Default behavior for this sync service was to follow symlinks, uploading the target (which is the desired behavior.) However it would only monitor the symlink for modification changes, not the target. This script bridges that gap. It also gives the added benefit of controlling how often syncs may occur, as you can set cron (or whatever) to run this script at an interval of your choosing.

This script works on Mac OS X 10.8 and has only been tested on such. It should work on other versions of OSX and is likely to work on various linux flavors (though I have noticed flags and behavior for the command “stat” differ between OS X and linux.)

Modify the above directory path, escaping any spaces, and leave the asterisk (*) on the end.

Leave a Reply