Here’s a short script that will check a specific directory for symbolic links and then:
- check the modification date of symlinks’ respective targets
- 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.)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
#!/bin/sh # # Compare modification of symlinks in directory with files they point to. # If original modificaiton date is newer than modification date of symlink, symlink is touched. # # for f in /put/your/full/directory/path/here/* do flink=`readlink "$f"` if [ ! -z "$flink" ] then if [ `stat -f "%Sm" -t "%Y%m%d%H%M%S" "$f"` -lt `stat -f "%Sm" -t "%Y%m%d%H%M%S" "$flink"` ] then touch -h "$f" fi fi done |
Modify the above directory path, escaping any spaces, and leave the asterisk (*) on the end.