I would like to determine if a file is older than a particular date. I found that istat will let me see the date and time of a file older than a year, but I need to change the format. Could anyone help me reformat the following date to a variable (a one liner would be great).
Output from istat - Last modified: Sat Oct 10 01:37:54 EDT 2009
capture date to a variable as - 200910100137 (yyyymmddHHMM)
if you have gnu date this should do it:
MODDATE=$(date --date "$(istat FILENAME | awk -F "\t" '/Last modified/ { print $2}') " +%Y%m%d%H%M)
If you get date: Not a recognized flag, then we really don't have a 1 liner any more:
$ cat ISO2ymd.awk
awk -F "[: ]" ' BEGIN {
D["Jan"]=1; D["Feb"]=2; D["Mar"]=3; D["Apr"]=4;
D["May"]=5; D["Jun"]=6; D["Jul"]=7; D["Aug"]=8;
D["Sep"]=9; D["Oct"]=10; D["Nov"]=11; D["Dec"]=12; }
{ printf "%04d%02d%02d%s%s\n", $9, D[$2], $4, $5, $6; }' -
$ MODDATE=$(istat FILENAME | awk -F "\t" '/Last modified/ { print $2}' | ./ISO2ymd.awk)