Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ryran/6029699 to your computer and use it in GitHub Desktop.
Save ryran/6029699 to your computer and use it in GitHub Desktop.
A bash function for making it easy to change the access time of a file
#!/bin/bash
# (To change mtime instead of atime, switch the -a to -m)
atime_change_1month_ago()
{
if [[ -e $1 ]]; then
month=`date +%m`
[ `echo $month|cut -c1` -eq 0 ] && month=`echo $month|cut -c2`
month=$((month - 1))
[ `expr length $month` -eq 1 ] && month="0$month"
DayHrMin=`date +%d%H%M`
touch -a -t ${month}${DayHrMin} "$1"
else
echo "$1: No such file or directory"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment