I am working on checking if a particular file existing in the directory is older than 30 mins or not.
curr_epch=`date +%s`
curr_epch_buff=`expr $curr_epch - 1800`
ls -l --time-style=+"%s" | grep .part | awk '{ if (($6 >= $curr_epch_buff)) print $6 }'
However the above code is giving me results irrespective of the condition mentioned.
To debug it, when i tried to take a difference between these 2 values also I am not getting expected results, instead the value in $6 is getting printed as it is:
ls -l --time-style=+"%s" | grep .part | awk '{ print (expr $6 - $curr_epch_buff) }'
However if i try to subtract a static number using above query, its giving me expected results:
ls -l --time-style=+"%s" | grep .part | awk '{ print (expr $6 - 200) }'
Can someone please tell me whats wrong with first and second set of codes mentioned above?
ls
to find files by age (use something likefind -mmin
instead) – steeldriver Mar 27 '20 at 16:26