Skip to content

Instantly share code, notes, and snippets.

@weblogix
Last active August 29, 2017 02:46
Show Gist options
  • Select an option

  • Save weblogix/85bfd6941335988cd52e65e6dddcc0bb to your computer and use it in GitHub Desktop.

Select an option

Save weblogix/85bfd6941335988cd52e65e6dddcc0bb to your computer and use it in GitHub Desktop.
[File date sync] Sync's the file dates between 2 folders with the same files #sync #script
#!/bin/bash
SOURCE_DIR=$1
DESTINATION_DIR=$2
find "$SOURCE_DIR" -print | while read filename; do
FILE_NAME="$(basename "$filename")"
SOURCE_PATH="$SOURCE_DIR/$FILE_NAME"
DESTINATION_PATH="$DESTINATION_DIR/$FILE_NAME"
if [ -f "$DESTINATION_PATH" ]
then
FILE_DATE="$(stat -f "%Sm" -t "%m/%d/%Y %H:%M" "$SOURCE_PATH")"
SetFile -d "$FILE_DATE" "$DESTINATION_PATH"
else
echo "$(basename "$filename") not found in $DESTINATION_DIR"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment