Find files older than 8 hours


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find files older than 8 hours
# 1  
Old 07-22-2010
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...

Code:
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
# 2  
Old 07-22-2010
how do you confirm that mmin is not working ?
# 3  
Old 07-23-2010
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.
# 4  
Old 07-24-2010
Thanks..If you could sent the same..it will be really helpful...
# 5  
Old 07-26-2010
Code:
# 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


Last edited by Scott; 07-26-2010 at 05:11 AM.. Reason: Please use code tags
This User Gave Thanks to digitalrg For This Post:
# 6  
Old 07-26-2010
Thanks..got the same working....
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Deleting Files Older than 1 hours.

How to Deleting Files Older than 1 hours. Base on SunOS. this file gen every 1 min. -rw-r--r-- 1 nobody nobody 4960 Jan 27 02:02 23_201301270201.log -rw-r--r-- 1 nobody amudu 2325 Jan 27 02:03 33_201301270202.log -rw-r--r-- 1 nobody amudu 3255 Jan 27 02:03... (2 Replies)
Discussion started by: ooilinlove
2 Replies

2. Shell Programming and Scripting

files older than few hours

Hi All I need to know the command which can be used to list the files which are 3 hours old so that it can be deleted. (3 Replies)
Discussion started by: mskalyani9
3 Replies

3. Shell Programming and Scripting

Deleting files older than 6 hours

Hi All, I am using the below script to find all the files in a folder which are older than 6 hours and delete all those files, but some how I am not getting the required output. find $HOME/Log -type f -name "*.log" -amin +360 -exec rm *.* {} \ can any one please check and let me know... (13 Replies)
Discussion started by: subhasri_2020
13 Replies

4. Shell Programming and Scripting

if condition for files older then 24 hours in direc

Hi all I have directory /tmp and i have logs are written in it every 18 to 20 hours in date format. now i need write some if condition which can find which files came into /tmp dir with name start from LOG_`date`.log in last 24 hours. can somebody help me on this. (2 Replies)
Discussion started by: tapia
2 Replies

5. AIX

how to find files older than 2 hours

I need help to find files in a directory that are older than 2 hours. Any help would be great. (3 Replies)
Discussion started by: pt14
3 Replies

6. Shell Programming and Scripting

unix command/s to find files older than 2 hours in a directory

I need to write a script to find files older than 2 hours in set of direcotries and list them ina mail. I know find command ti list files greater/lesser than days but i need to do it for hours. Any input. (6 Replies)
Discussion started by: Presanna
6 Replies

7. Solaris

Deleting Files Older than 24 hours

Hi, I am using Solaris Box, I need to delete file(cookies.html) from the path(/usr/temp) which are older than 24 hours(I want in hours, not in days) Can u provide the command for the above query (7 Replies)
Discussion started by: mazhar803
7 Replies

8. Shell Programming and Scripting

removing files after 6 hours or older

What is the command to remove files that are generated 6 hours or older? The find and remove tells only how to remove if the file is one day old or more. Appreciate quick reply. Thanks (3 Replies)
Discussion started by: gthokala
3 Replies

9. UNIX for Dummies Questions & Answers

Finding only those files older than 2 hours

I need to write a program that will only remove those files that are older than 2 hours. Is there some variation of find . -mtime ? -name '*' that I can use? Thanks as always for your help. Regards, Dave :) (2 Replies)
Discussion started by: mh53j_fe
2 Replies

10. Shell Programming and Scripting

Finding files older than 2 hours

I want to write a sh script that will find files older than 2 hours and tar them. I've had a look at the find man page but can't see how to do it by hours. Help please. Thanx (1 Reply)
Discussion started by: ianf
1 Replies
Login or Register to Ask a Question