Command to find files older than 1 hour


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Command to find files older than 1 hour
# 1  
Old 12-12-2014
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
# 2  
Old 12-12-2014
Below timestamp corresponds to YYMMDDHHMM, please adjust it for your requirement; if required, YYYYMMDDHHMMSS should work too (see man touch).
Code:
touch -t 1412121200 /tmp/newer

(Alternatively, you could use a reference file to take its timestamp, e.g. touch -r /path/to/reffile /tmp/newer)
Code:
find /path/to/dir -type f ! -newer /tmp/newer

Make sure you "update" your /tmp/newer file accordingly if you run find again at a later date.
# 3  
Old 12-12-2014
The problem is I cannot hardcode the timestamp for the temp file. Since this is a script which will run every 1 hour, I want to pick only those files which were created one hour before the current timestamp.
# 4  
Old 12-12-2014
If you run the script regularly, keep the directory's last contents and compare to the actual state.
Code:
ls -1 >old
touch Xx YY
ls -1 | grep -vf old
Xx
YY

# 5  
Old 12-12-2014
First see if
Code:
date "+%y%m%d%H%M%S"

will work. That will give you the current timestamp one could feed to touch.

I don't know much HP-UX, but on Linux and Solaris 10, one can temporarily change the TZ (timezone) variable.

One could (ab)use it like so:
Code:
ts=`TZ="America/Los_Angeles" date "+%y%m%d%H%M%S"`

Make sure you use an appropriate and valid Continent/City combination that is 1 hour behind your current location.

If it works, you could try touch -t $ts /tmp/newer

If the current value of TZ is something like PST8PDT, try the Continent/City combination anyway.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

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

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

3. UNIX for Dummies Questions & Answers

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; # 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... (4 Replies)
Discussion started by: Siva SQL
4 Replies

4. Shell Programming and Scripting

Find command to search and delete files older than 1 days at a desired location

Hello All, Can someone please help me out in creating the find command to search and delete files older than 1 days at a desired location. Thanks in advance for your help. (3 Replies)
Discussion started by: Pandee
3 Replies

5. Shell Programming and Scripting

find command to filter specific type of files older than certain date.

Hi I need to find the list of files in a directory and to do some specific operations based on the type of files. suppose in a directory am having .dat , .log, .err, .rej file types. i need to filter out .dat and .log only which are older than six months. i used the below query but the... (2 Replies)
Discussion started by: msathees
2 Replies

6. Shell Programming and Scripting

Finding older files using find command

Hi All, I want to find files which are older than 15 days. I have written a command as below, find -mtime +15 -print I understand (System date - last modified time of a file) should be greater than or equal to 15 days. This command returns files which are 15 days old.. i.e... (1 Reply)
Discussion started by: nshan
1 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