Operating System - Linux
1753432 Members
4581 Online
108793 Solutions
New Discussion

How to get a file's year of last modification by SHELL?

 
MA Qiang
Regular Advisor

Re: How to get a file's year of last modification by SHELL?

I write a shell(awk) script for it. Please check it. Thanks.

$ get_file_date.sh lost+found
20041127
drwxr-xr-x 2 root root 96 Nov 27 2004 lost+found

$ cat get_file_date.sh
d_filedate=`ls -ld $1|awk '{
month["Jan"]="01"
month["Feb"]="02"
month["Mar"]="03"
month["Apr"]="04"
month["May"]="05"
month["Jun"]="06"
month["Jul"]="07"
month["Aug"]="08"
month["Sep"]="09"
month["Oct"]="10"
month["Nov"]="11"
month["Dec"]="12"
{"date +%Y"|getline YYYY; "date +%m"|getline MM};
if (index($8,":") > 0 && month[$1]>MM) {printf ("%s", YYYY-1)};
if (index($8,":") > 0 && month[$1]<=MM) {printf ("%s", YYYY)};
if (index($8,":") == 0) {printf ("%s", $8)};
printf("%s%02d",month[$6],$7) }'`
echo $d_filedate
ls -ld $1