finding files N hrs old


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting finding files N hrs old
# 1  
Old 12-10-2010
finding files N hrs old

I know you can supply the find command with an option to find files > than N days old. Is there some way to do this to find files that are > than N hours old.

I want to do somthing like this:

find . -mtime + (now - 2hrs) -print

If not is there a way to do this with sed or awk or some KSH shell script code?
# 2  
Old 12-10-2010
Some find implementations support the -mmin switch:

Code:
find . -mmin -$((2*60))

If that's not an option, you could use Perl:

Code:
perl -MFile::Find -le'
  find { 
    wanted => sub {
      (2/24) > -M and print $File::Find::name
      }
    }, shift    
  ' .

# 3  
Old 12-11-2010
Use the touch command with the -t option to create a file with a specific datestamp. Then use find with -newer against your dated file.
# 4  
Old 12-11-2010
There is much variation in "find" and "date" commands.
What Operating System and version do you have?
What Shell do you prefer?
# 5  
Old 12-12-2010
This is AIX 5.3 and Solaris 2.10. It needs to work in KSH and be portable across these platforms
# 6  
Old 12-12-2010
In AIX 5.3 you can do (adjust TZ setting for your region), Don't have access to solaris 2.10 to test against but it should be pretty close:

Code:
WHEN=$(TZ=GMT-8 ; date +%m%d%H%M)
touch -t $WHEN /tmp/REF.$$
find /my/path -newer /tmp/REF.$$ -print
rm /tmp/REF.$$


Last edited by Chubler_XL; 12-12-2010 at 07:58 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Been working since 25+ hrs: Bash Script to rename files supposedly direct but difficult to execute

:wall::wall::wall: Hi I have horrible script below, need help in renaming ls -l output into new filename format: Desired output: cp -pv original_path/.* newDirectory/owner_of_file.%dd%mm%y.file_extension.first_8_characters_of_original_filename localuser@localuser:~ vi... (3 Replies)
Discussion started by: wolf@=NK
3 Replies

2. Shell Programming and Scripting

Finding files with wc -l results = 1 then moving the files to another folder

Hi guys can you please help me with a script to find files with one row/1 line of content then move the file to another directory my script below runs but nothing happens to the files....Alternatively Ca I get a script to find the *.csv files with "wc -1" results = 1 then create a list of those... (5 Replies)
Discussion started by: Dj Moi
5 Replies

3. Shell Programming and Scripting

To delete files older than 24 hrs

I have to retain only 1 day files in my system an I have to delete all the other files which are older than 24 hrs. Please let me know the option I have to give in the find -mtime command. (3 Replies)
Discussion started by: rajesh8s
3 Replies

4. Shell Programming and Scripting

List last 10 Hrs file and find error files

Hi, I need a script that can search a word "Error" in last 10 Hrs generated logs in /log/App1 and /log/App2 folder.. Note these directories have massive log files ...actually our application generate 100 Log files of size 2MB in just a min so script must be fast enough to cater this I... (9 Replies)
Discussion started by: Mujtaba khan
9 Replies

5. Shell Programming and Scripting

Find files in a directory which are older than 2 hrs

hi all, I need to find files in a directory which are older than N hrs... n can be 1,2,3,.. etc when tried using -mtime option it gives all the files in the last 24hrs from the current time . please help me out on this .. thanks (8 Replies)
Discussion started by: sparks
8 Replies

6. UNIX for Dummies Questions & Answers

How to list files Created in last 2 hrs

I wanted to know what command should I use to see the files created in last 2 hours in a given directory. I know to see the files changed in last one day I can use this: find /admin//dump -type f -ctime -1 -print | xargs ls -lt|pg However I am not getting what should I use if I wanted tol... (4 Replies)
Discussion started by: rsonakiya
4 Replies

7. Shell Programming and Scripting

check for new file over 24 hrs

Hi all, I am trying to figure out a method to flag an error if a file has not arrived in a certain directory within 24 hrs of the last one arriving. I am currently writing the time to a file when a file is recieved. I then want to check for a new file reguarly but flag an error if it has been... (3 Replies)
Discussion started by: pxy2d1
3 Replies

8. Shell Programming and Scripting

modifying grep to get files only within last 2 hrs

Hi gurus I am currently using the below mentioned grep to find timestamp of last generated log file. touch -t $time_search dummy ecust_time_stamp=$(find . -name 'eCustomerCME*' -newer dummy -type f -exec ls -ltr {} \; | tail -1 | awk ' { print $6,$7,$8 } ') I calculate... (3 Replies)
Discussion started by: ragha81
3 Replies

9. Shell Programming and Scripting

finding duplicate files by size and finding pattern matching and its count

Hi, I have a challenging task,in which i have to find the duplicate files by its name and size,then i need to take anyone of the file.Then i need to open the file and find for more than one pattern and count of that pattern. Note:These are the samples of two files,but i can have more... (2 Replies)
Discussion started by: jerome Sukumar
2 Replies

10. UNIX for Dummies Questions & Answers

TZ out by 12 hrs

Is there a way of setting the TZ for New Zealand. I do not mind if it is only for the logged in session. It makes it hard to understand when files or CRON jobs have run when the time is set to GMT0. Any help will be appreciated. ;) (1 Reply)
Discussion started by: jagannatha
1 Replies
Login or Register to Ask a Question