The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Finding modified File List after the chosen date in Korne Shell... marconi Shell Programming and Scripting 2 01-22-2008 05:27 AM
Finding only those files older than 2 hours mh53j_fe UNIX for Dummies Questions & Answers 2 07-01-2005 09:33 AM
Finding modified files rhayabusa UNIX for Dummies Questions & Answers 2 12-16-2004 01:48 PM
finding date and time after 3 hours svannala High Level Programming 2 09-07-2003 11:07 PM
Finding files older than 2 hours ianf Shell Programming and Scripting 1 05-27-2002 10:51 AM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-20-2008
trichyselva trichyselva is offline
Registered User
  
 

Join Date: Feb 2006
Posts: 65
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 (permalink)  
Old 03-20-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,717
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 (permalink)  
Old 06-04-2009
Bill Ma Bill Ma is offline
Registered User
  
 

Join Date: Jun 2009
Posts: 5
Quote:
Originally Posted by jim mcnamara View Post
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
  #4 (permalink)  
Old 03-20-2008
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,513
Quote:
Originally Posted by trichyselva View Post
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.
  #5 (permalink)  
Old 03-21-2008
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,847
With zsh:

Code:
print -l **/*(.mh-2)
  #6 (permalink)  
Old 06-04-2009
devtakh devtakh is offline
Registered User
  
 

Join Date: Oct 2007
Location: Bangalore
Posts: 514
or touch a file with the timestamp
and then use find with the option -newer


-Devaraj Takhellambam
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:49 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0