Last active
January 11, 2022 11:52
-
-
Save kou1okada/40a2c2596419c414631107b6dde614b8 to your computer and use it in GitHub Desktop.
fixtimestamp.sh - fix timestamp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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