Find files older than 8 hours

I need a script to find files older than 8 hours...
I know i can use mmin but the same is not working...the same only support mtime...

This is the script i created..but the same is only giving 1 hour old..as I have given dt_H as 1 only...but if i give 8..it can go in -(negative)..how to get the result...

dt_H1=`date +%H`
dt_H=0`expr ${dt_H1} - 1`
dt_M=`date +%b`
dt_D=`date +%d`
cd /u02/archive/PWR
rm -rf `ls -ltr | awk '{print $6 " " $7 " " $8 " " $9}'| sed -n '/'"$dt_M"' '"$dt_D"' '"$dt_H"'/p' | awk '{print $4}'`

Thanks

how do you confirm that mmin is not working ?

You can also do like this.
touch a file xyz.txt which has time stamp 8 hours before by using per 1 liner (/usr/bin/perl -le 'print scalar localtime (time() - 480*60);' )
get this date & time to the format YYYYMMDDHHMM used for the touch -t YYYYMMDDHHMM
then use the find command to get the files that are older than this touched file as below
find <path> -type f ! -newer xyz.txt -print
Let me know if you want exact script, i have it handy.

Thanks..If you could sent the same..it will be really helpful...

# Get the 8 hours old date & time stamp 
Y_DAY=`/usr/bin/perl -le 'print scalar localtime (time() - 480*60);' `
Y_YR=`echo $Y_DAY | awk '{print $5}'`
Y_MON=`echo $Y_DAY | awk '{print $2}'`
Y_DT=`echo $Y_DAY | awk '{print $3}'`
Y_HR=`echo $Y_DAY | awk '{print $4}' | cut -d":" -f1 `
Y_MIN=`echo $Y_DAY | awk '{print $4}' | cut -d":" -f2 `

# Convert Month name to month number
case $Y_MON in

"Jan") NEW_Mon=01
;;

"Feb") NEW_Mon=02
;;

"Mar") NEW_Mon=03
;;

"Apr") NEW_Mon=04
;;

"May") NEW_Mon=05
;;

"Jun") NEW_Mon=06
;;

"Jul") NEW_Mon=07
;;

"Aug") NEW_Mon=08
;;

"Sep") NEW_Mon=09
;;

"Oct") NEW_Mon=10
;;

"Nov") NEW_Mon=11
;;

"Dec") NEW_Mon=12
;;

*) echo "Invalid output"
;;

esac

REF_DT_STAMP=`echo $Y_YR$NEW_Mon$Y_DT$Y_HR$Y_MIN `
#echo $REF_DT_STAMP

# create a file in the home dir for the reference
FILE_NEW="$HOME/testing_file.txt"
touch -t $REF_DT_STAMP $FILE_NEW


# find files that are older than this file
find <path> -type f ! -newer $HOME/testing_file.txt -print




# delete the reference file 
rm $FILE_NEW
1 Like

Thanks..got the same working....