Checking file existence along with condition

Hi am trying to write a script which find the existence of a file from a find command output and perform a task if the file exists. Help me out with the correct syntax . Am trying with the following one but unable to get the output.

if [-f find <path> -mtime 4 -print ]
then <some tasks>
else
echo "file not exists"
fi

find returns only the exists file/folder

may be you need to redirect the warning/error to /dev/null ?

 find <path> -mtime 4 -print 2>/dev/null | while read file; do echo "process the file $file"; done

Thanks for your reply.
Am not getting the output what am expecting. My requirement is to check the existence of a file using the find command and if the file exists have to perform some tasks. Any help on this will be really helpful

find /path -type f -name "filename" | while read a;
do
echo "do process here"
done

why do you need to check the file existence using find command ? you can simply check it like

if [ -f filename.txt ]
then
    echo "file present"
else
   echo "no file"
fi

find does not "find" non-existent files, so having find test to see if a file exists is, well, a waste to put a happy face on it.

Also -mtime 4 means the file is precisely (86400 * 4) old. The result of running this changes with every second that passes between runs. I suspect you want 4 day old files,
from midnight to midnight.

So, today is 201207090000 is the date format that touch uses.
4 days ago is encompassed by: 201207050000 201207052359

touch -t  201207050000  dummy1
touch -t 201207052359 dummy2
find /path/to/files \( -newer dummy1 -a  ! -newer dummy2 \) |
while read filename
do
    # some tasks on $filename
done

Please post what Operating System and version you have and what Shell you are using.

my_hitlist=/tmp/my_hitlist.$$
start_dir="/path/to/start/directory"
filename="the_name_of_the_file"
find "${start_dir}" -xdev -name "${filename}" -type f -print 2>/dev/null > ${my_hitlist}
# Did we find any files?
if [ -s ${my_hitlist} ]
then
       # Do some tasks
else
       echo "File does not exist: ${start_dir}/${filename}"
fi      

No idea where -mtime 4 comes into it.

Hmm. Popular type of question. Homework?

If there is just one file and you know the full path to the file, this can be simplified in most versions of find .