HP UNIX: How to find files which are older than one hour.


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers HP UNIX: How to find files which are older than one hour.
# 1  
Old 07-16-2013
HP HP UNIX: How to find files which are older than one hour.

HP Unix Version: HP-UX B.11.31 U ia64

Question
I look for script or command to find files which are older than one hour.

Tried below;

Code:
# set the file time to 1 hours ago
touch -t 201307160700 ./touchfile

find /app/grid/product/11.2.0.3/rdbms/audit -name '*.aud' -type f ! -newer touchfile | wc -l

But I am not getting the result.

Is my command syntax correct?

I am doubting on ! -newer part, please advise.
# 2  
Old 07-16-2013
Works for me!

No cd between touch and find? touchfile looks good on ls -l?
# 3  
Old 07-18-2013
What output do you get? Are you expecting file names, or just a number?

What do you plan to do next with the results?



Robin
Liverpool/Blackburn
UK

Last edited by rbatte1; 07-18-2013 at 01:31 PM.. Reason: Nationallity on Signature
# 4  
Old 07-18-2013
try the -mtime or -mmin options.. i do not remember the correct syntax but one of these two will surely do it.

Code:
find . -type f -mtime +1

or

Code:
find . -type f -mmin +60

# 5  
Old 07-19-2013
So, to work out the timestamp to generate the reference file you can use the date command on it's own if your system supports the options like this:-
Code:
touch -mt `date +%Y%m%d%H%M%S --date='1 hour ago'` /tmp/ref_file
find trg_dir -type f ! -newer /tmp/ref_file -name "*.aud"

If your OS does not support those date arguments, then you can play with the TZ variable to acheive the same result, thus:-
Code:
#!/bin/ksh
Orig_TZ="$TZ"
Offset=`echo $TZ|cut -f1 -d "," | tr -d "A-Z"`      # Get the numeric bit
P1_TZ="${TZ%%${Offset}*}"                           # Get the first part of the TZ
P2_TZ="${TZ#*${Offset}}"                            # Get the rest of the TZ after the offset

((Offset=$Offset+1))                                # Increase the value by one hour
TZ="${P1_TZ}${Offset}${P2_TZ}"                      # Set new timezone

ref_date=`date +%Y%m%d%H%M%S`                       # Get the value based on our adjusted TZ
TZ="$Orig_TZ"                                       # Reset back to original

touch -mt ${ref_date} ref_file

find trg_dir -type f ! -newer /tmp/ref_file -name "*.aud"


Does this suit your needs? Rather than use the TZ variable, you could of course get the values from the date command and build it up yourself, just taking one away from the hours, but then you'd have to handle going back past midnight, so change of day/month/year and it would get messier.


I hope that this helps, but if not, please explain what's wrong and what you need.


Robin
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Command to find files older than 1 hour

Hi, Out of a list of files in a directory, I want to find the files which were created/modified more than 1 hour ago. I am using HP -UNIX and it does not support the argument -mmin. Please advise. I am using # !/bin/sh (4 Replies)
Discussion started by: jhilmil
4 Replies

2. Shell Programming and Scripting

How to find the files created within one hour in Solaris?

Hi Gurus, I want to find the file created within one hour in solaris. I have tried below command, but it is no lucky. $find . -mtime -1/24, -name "abc*" above command give me the file name which created two hours ago find . -cmin -60, -name "abc*" above command I got error as... (4 Replies)
Discussion started by: ken6503
4 Replies

3. Shell Programming and Scripting

List last 1 hour files with out FIND command

Hi Friends, Can we have an alternate command to list last 1hour files with out FIND command? Thanks Suresh (6 Replies)
Discussion started by: suresh3566
6 Replies

4. Shell Programming and Scripting

Find and delete files and folders which are n days older from one unix server to another unix server

Hi All, Let me know how can i find and delete files from one unix server to another unix server which are 'N' days older. Please note that I need to delete files on remote unix server.So, probably i will need to use sftp, but question is how can i identify files and folders which are 'N'... (2 Replies)
Discussion started by: sachinkl
2 Replies

5. UNIX for Dummies Questions & Answers

Find files older than 2010?

Hi, I need to delete all files, in a folder, older than 2010 that is 2009, 2008 ,.. files... Can anyone suggest the command for that,... Thanks ---------- Post updated at 03:29 PM ---------- Previous update was at 02:53 PM ---------- humm,.. ok right now I am using the following:... (4 Replies)
Discussion started by: Mack1982
4 Replies

6. Shell Programming and Scripting

Find files modified in last hour sunOS 5.10

trying to find a way to locate files modified in the last hour in a shell script, unfortunately the command 'find . -mmin -60' is not supported on SunOS 5.10 (works on OpenSolaris 5.11 :mad:) Does anyone know a method of doing this in shell script on 5.10? cheers (19 Replies)
Discussion started by: rich@ardz
19 Replies

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

8. Shell Programming and Scripting

display the files in a folder which are older than 1 hour

Hi, I have some files in a folder with different time stamps and I want to display the files which are older than 1 hour. i tried with find. need urgent help. (7 Replies)
Discussion started by: vgs
7 Replies

9. UNIX for Dummies Questions & Answers

display the files in a folder which are older than 1 hour

Hi, I have some files in a folder with different time stamps and I want to display the files which are older than 1 hour. i tried with find. need urgent help. (3 Replies)
Discussion started by: vgs
3 Replies

10. Shell Programming and Scripting

Find files older than 20 days & not use find

I need to find files that have the ending of .out and that are older than 20 days. However, I cannot use find as I do not want to search in the directories that are underneath the directory that I am searching in. How can this be done?? Find returns files that I do not want. (2 Replies)
Discussion started by: halo98
2 Replies
Login or Register to Ask a Question