Skip to content

Instantly share code, notes, and snippets.

@kou1okada
Last active January 11, 2022 11:52
Show Gist options
  • Save kou1okada/40a2c2596419c414631107b6dde614b8 to your computer and use it in GitHub Desktop.
Save kou1okada/40a2c2596419c414631107b6dde614b8 to your computer and use it in GitHub Desktop.
fixtimestamp.sh - fix timestamp
#!/usr/bin/env bash
#
# fixtimestamp.sh - fix timestamp
# Copyright (c) 2019 Koichi OKADA. All rights reserved.
# This script is distributed under the MIT license.
#
if (( $# <= 0 )); then
cat <<-EOD
Usage: ${0##*/} [OPTIONS] <shifted_time> <correct_time> [<files> ...]
EOD
exit
fi
SHIFTED_TIME="$(date -d "$1" "+%s.%N")"
CORRECT_TIME="$(date -d "$2" "+%s.%N")"
shift 2
for i; do
TIME="$(date -r "$i" "+%s.%N")"
FIXED_TIME=$(perl -e "print $TIME - $SHIFTED_TIME + $CORRECT_TIME" )
echo touch -d \"@$FIXED_TIME\" \"$i\"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment