Sponsored Content
Top Forums Shell Programming and Scripting Find files older than 8 hours Post 302440046 by digitalrg on Monday 26th of July 2010 02:43:23 AM
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:
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
print(1)							   User Commands							  print(1)

NAME
print - shell built-in function to output characters to the screen or window SYNOPSIS
ksh print [ -Rnprsu [n]] [arg...] DESCRIPTION
ksh The shell output mechanism. With no flags or with flag - or -, the arguments are printed on standard output as described by echo(1). OPTIONS
The following options are supported: -n suppresses new-line from being added to the output. -R -r (raw mode) ignore the escape conventions of echo. The -R option will print all subsequent arguments and options other than -n. -p causes the arguments to be written onto the pipe of the process spawned with |& instead of standard output. -s causes the arguments to be written onto the history file instead of standard output. -u [ n ] flag can be used to specify a one digit file descriptor unit number n on which the output will be placed. The default is 1. EXIT STATUS
The following exit values are returned: 0 Successful operation. >0 Output file is not open for writing. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ SEE ALSO
echo(1), ksh(1), attributes(5) SunOS 5.10 15 Apr 1994 print(1)
All times are GMT -4. The time now is 05:15 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy