get_age() { local file=$1 local modtime=$(stat -c %Y $file) local now=$(date +%s) local diffdays=$(((now - modtime) / 86400)) echo $diffdays } # Example use file=myfile.txt days=$(get_age $file) echo "$file is $days old"Assumes a day has 24 hours * 60 seconds per hour * 60 seconds per minute = 86400 seconds. Does not take time changes (spring forward, fall back) into account.
Programming Tips - bash: get file age (in days)
Date: 2020jun11
OS: LInux
Language: bash
Q. bash: get file age (in days)
A.