0

I read a file which have all the file names line by line which ($var) returns the file names in the directory /home/mydir .

input="/home/mydir/test/myfile"
while IFS= read -r var
do
/home/mydir/"$var"
done < "$input"

Now i want to find whether the file is in that directory for more than 5 hours in a if loop.

How to do that ?

1 Answers1

1

Ah, thanks to comment by yeti:

edit again, oops, need input:

filetime=$(stat -c "%Z" "$input")
now=$(date "+%s")

age=$(($now - $filetime))

if (($age >= 18000)); then
   echo "File is OLD"
else
   echo "File is NEW"
fi
  • Thanks TiberiusKirk. I like to use ctime to find the time of the file. can you help me with that? – VRVigneshwara Sep 06 '15 at 13:53
  • That's a job for stat(1). –  Sep 06 '15 at 14:02
  • I'm not sure what you mean by "ctime". Do you mean the C function or the parameter of the "find" utility. The $filetime in the script above is the last modification time of the file. – TiberiusKirk Sep 06 '15 at 14:12
  • yes like modification time , I need to use change time . We have three types of time right access time, modification time and change time. For finding the time of the file i used 'find . -cmin -240' to get the files having change time greater than 4 hours. but don't know how to check for a particular file by specifying it's file name – VRVigneshwara Sep 06 '15 at 14:22
  • Thanks to comment by yeti, I edited the answer to suit your needs. – TiberiusKirk Sep 06 '15 at 14:41