Check age of the file

hi,
i am working on a shell script where i have 2 files & i need to check age of those files. one file should be of the same day and other shoudn't be more then 20 days old.

how could i acheive this? please help!!!!

Read about the -mtime switch of the find command.

i have used this earlier but i was getting some error:

bash-3.2$ find /apps/vcred/appl/vcrdftp/put/ecredit_drop -iname "1181*.dat" -mtime -60 -print
find: bad option -iname
find: [-H | -L] path-list predicate-list

then i used name instead of using iname:
bash-3.2$ find /apps/vcred/appl/vcrdftp/put/ecredit_drop -name "1181*.dat" -mtime -60 -print
/apps/vcred/appl/vcrdftp/put/ecredit_drop/1181_dnb_dv_load.dat

what does it mean by -iname/name? please help

find /apps/vcred/appl/vcrdftp/put/ecredit_drop -iname 1181\*.dat -mtime -60 -print

above must work can you please check it

-iname pattern
Like -name, but the match is case insensitive.

find file1 -mtime 0
find file2 -mtime +20

A | grep . also sets the exit status so you can do

if find file1 -mtime 0 | grep . >/dev/null
then
 echo "file1 is less than 24 hours old"
fi

Another way is [test]

if [ -n "`find file1 -mtime 0`" ]
then
 echo "file1 is less than 24 hours old"
fi

i have to use both of these conditions at once only, like both of the condition should be satisfied then i'll work on sending email further...

i think we can use variables for both of those files and if status of both of the variables are true then we can send email..

but can anyone help me to use the same logic through code please..

No, it must not. -iname is an extension to the standard which is not supported by every find implementation.

Regards,
Alister

Combined with a && = AND condition:

if [ -n "`find file1 -mtime 0`" ] &&
 [ -n "`find file2 -mtime +20`" ]
then
 echo "\
file1 is younger than 24 hours and
file2 is older than 20 days."
fi

With many find's, in this instance it's possible to test the exit status directly. Whether the following is good practice is something I'll leave for others to decide.

find file1 ! -mtime 0 -exec false {} +    &&     find file2 ! -mtime +20 -exec false {} +

Regards,
Alister

Well, to be sure it is 20 not 21, you need '! -mtime +21' in the mix, eh?