finding the file which is modified within last 2 hours


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting finding the file which is modified within last 2 hours
# 1  
Old 03-20-2008
finding the file which is modified within last 2 hours

hi,
I want to find a file which is modified within last 2 hours
i am using sun-os
i tried find . -name <filename> -mmin 120

i found that mmin option is not supported in sun-os is there any other alternative option

suggestions welcome

thanks in advance
# 2  
Old 03-20-2008
You need perl, python or C - here is perl
Code:
#!/bin/ksh
secs()
{
	perl -e ' 
			 $mtime = (stat $ARGV[0])[9];
			 $diff = time() - $mtime;
			 if ($diff > ( $ARGV[1] * 3600 )) 
			 {
			     print "1";	
			 }
			 else
			 {
			     print "0";	
			 }
			' $1  $2
}
hours=2
for file in `ls *.pl`
do
	older=$(secs $file $hours)
	if [[ $older -eq 1 ]] ; then
	   echo "$file is older"
	else
	   echo "$file is not older"
	fi   
done

# 3  
Old 03-21-2008
Quote:
Originally Posted by trichyselva
hi,
I want to find a file which is modified within last 2 hours
i am using sun-os
i tried find . -name <filename> -mmin 120

i found that mmin option is not supported in sun-os is there any other alternative option

suggestions welcome

thanks in advance
please try the mtime option. check the man page of find.
# 4  
Old 03-21-2008
With zsh:

Code:
print -l **/*(.mh-2)

# 5  
Old 06-04-2009
Quote:
Originally Posted by jim mcnamara
You need perl, python or C - here is perl
Code:
#!/bin/ksh
secs()
{
    perl -e ' 
             $mtime = (stat $ARGV[0])[9];
             $diff = time() - $mtime;
             if ($diff > ( $ARGV[1] * 3600 )) 
             {
                 print "1";    
             }
             else
             {
                 print "0";    
             }
            ' $1  $2
}
hours=2
for file in `ls *.pl`
do
    older=$(secs $file $hours)
    if [[ $older -eq 1 ]] ; then
       echo "$file is older"
    else
       echo "$file is not older"
    fi   
done

What is the first check for? -- comparing diff to 3600
# 6  
Old 06-04-2009
or touch a file with the timestamp
and then use find with the option -newer


-Devaraj Takhellambam
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Find command to get the modified files past 2 hours

Hello, How to get the modified/created files past 2 hours in Solaris with find command? Thank you. (7 Replies)
Discussion started by: balareddy
7 Replies

2. Shell Programming and Scripting

Help with finding the latest modified version of a file within directories

I am trying to look into multiple directories and pluck out the latest version of a specific file, regardless of where it sits within the directory structure. Ex: The file is a .xls file and could have a depth within the directory of anywhere from 1-5 Working directory - Folder1... (6 Replies)
Discussion started by: co21ss
6 Replies

3. UNIX for Advanced & Expert Users

find files modified by hours instead of minutes

Is there an easy way to find files modified by hours? If you wanted to find something modified by like 28 hours then I know you could do this: find . -mmin -1440It is pain to break out a calculator and calculate in minutes. Could you do something similar to this? I know I don't have the right... (1 Reply)
Discussion started by: cokedude
1 Replies

4. Homework & Coursework Questions

list of files modified 10 hours ago using grep

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Here is the question: Make a list of files in your home directory that were changed less that 10 hours ago,... (3 Replies)
Discussion started by: fight4love
3 Replies

5. Shell Programming and Scripting

Test if a file has a last modified date of within the last 24 hours

Hi there Im trying to find a way to test whether the last modified time is older than 1 day or not so #!/bin/bash if ; then $TOUCHED = "recently" else $TOUCHED = "not so recently" fi ive seen loads of posts where people are using find and the -mtime property but i... (2 Replies)
Discussion started by: rethink
2 Replies

6. UNIX for Advanced & Expert Users

Finding the modified date time of a file

Hi, I am new bie to Unix. Might be a simple question I am asking. I want to find the last modified time of a file and find the difference between the currrent time and the last modified time. Appreciate, if someone can throw some light on what commands can be used. Cheers, James (2 Replies)
Discussion started by: JamesJoe
2 Replies

7. Shell Programming and Scripting

Finding the list of users who modified a file

Dear all, Need a quick help/suggestion on monitoring a particular directory . We have a deployment directory say (/users/integration/deploy ) under this there are several files which can be edited by a number of users - We need to write a script which will check this deployment directory... (5 Replies)
Discussion started by: jambesh
5 Replies

8. UNIX for Dummies Questions & Answers

Finding a file created within the last 24 hours

which out of atime, ctime, or mtime are the closest to diplaying only the files created within the last 24 hours. is it even possible to find only the files created in the last 24 hours, because I heard that unix files don't hold the creation time as a property of the file. (3 Replies)
Discussion started by: raidkridley
3 Replies

9. Shell Programming and Scripting

Finding modified File List after the chosen date in Korne Shell...

I am trying to write a Korne Shell asking the user for a date and a directory and then search recursively in this directory the list of files modified after the date chosen. But I am not getting good results when I Test it... #!/usr/bin/ksh echo "Enter a date (YYYYMMDD) " read date touch -t... (2 Replies)
Discussion started by: marconi
2 Replies

10. 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
Login or Register to Ask a Question