Find files modified in last hour sunOS 5.10 | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


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

Find files modified in last hour sunOS 5.10

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 07-13-2010
rich@ardz rich@ardz is offline
Registered User
 
Join Date: Apr 2010
Last Activity: 22 February 2012, 5:05 AM EST
Posts: 52
Thanks: 12
Thanked 0 Times in 0 Posts
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 )

Does anyone know a method of doing this in shell script on 5.10?

cheers
Sponsored Links
    #2  
Old 07-13-2010
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
 
Join Date: Feb 2004
Last Activity: 19 September 2014, 10:01 PM EDT
Location: NM
Posts: 10,211
Thanks: 278
Thanked 796 Times in 743 Posts

Code:
filetime()  # create a filetime x hours ago
{
perl -e '      
      $mtime = time - (3600 * $ARGV[0]);

      # time structure into variables

      ($sec,$min,$hr,$day,$mon,$yr,$wday,@dntcare) = localtime($mtime);
      $yr = ($yr>=70) ? $yr+1900 : $yr+2000;
      $mon += 1;
      printf ("%d%02d%02d%02d%02d", $yr,$mon,$day,$hr,$min); ' "$1"
}
# get file time in YYYYMMddhhmm format
oldtime=$(filetime 1)

touch -t $oldtime dummy
find /path/to/files -newer dummy -print

Sponsored Links
    #3  
Old 07-13-2010
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
Moderator
 
Join Date: Jan 2007
Last Activity: 20 September 2014, 5:20 AM EDT
Location: Варна, България / Milano, Italia
Posts: 5,674
Thanks: 182
Thanked 620 Times in 578 Posts
Another one:


Code:
perl -MFile::Find -le'
  find { 
    wanted => sub {
      -f and 1 / 24 >= -M and print $File::Find::name;
      }
    }, shift    
  ' <dirname>

-f is for regular files, you can modify it, if you need something different.

Last edited by radoulov; 07-13-2010 at 01:41 PM.. Reason: Corrected.
    #4  
Old 07-13-2010
rich@ardz rich@ardz is offline
Registered User
 
Join Date: Apr 2010
Last Activity: 22 February 2012, 5:05 AM EST
Posts: 52
Thanks: 12
Thanked 0 Times in 0 Posts
many thanks for these replies guys, is there a way to do this via shell and not perl?
Sponsored Links
    #5  
Old 07-13-2010
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
Moderator
 
Join Date: Jan 2007
Last Activity: 20 September 2014, 5:20 AM EDT
Location: Варна, България / Milano, Italia
Posts: 5,674
Thanks: 182
Thanked 620 Times in 578 Posts
Why? What's the problem with Perl?
The Following User Says Thank You to radoulov For This Useful Post:
Gem_In_I (04-29-2012)
Sponsored Links
    #6  
Old 07-13-2010
rich@ardz rich@ardz is offline
Registered User
 
Join Date: Apr 2010
Last Activity: 22 February 2012, 5:05 AM EST
Posts: 52
Thanks: 12
Thanked 0 Times in 0 Posts
non whatsoever, just wondering if it can be accomplished in shell

---------- Post updated at 03:21 PM ---------- Previous update was at 03:15 PM ----------


Code:
#!/usr/bin/ksh

# perl -MFile::Find -le'
  # find { 
    # wanted => sub {
      # -f and 1 >= -M and print $File::Find::name;
      # }
    # }, shift    
  # ' <dirname>
  
LOGS=/export/home/richard/share
  
  filetime()  # create a filetime x hours ago
{
perl -e '      
      $mtime = time - (3600 * $ARGV[0]);

      # time structure into variables

      ($sec,$min,$hr,$day,$mon,$yr,$wday,@dntcare) = localtime($mtime);
      $yr = ($yr>=70) ? $yr+1900 : $yr+2000;
      $mon += 1;
      printf ("%d%02d%02d%02d%02d", $yr,$mon,$day,$hr,$min); ' "$1"
}
# get file time in YYYYMMddhhmm format
oldtime=$(filetime 1)

touch -t $oldtime dummy

find $LOGS -newer dummy -print

-bash: ./perl.ksh: /usr/bin/ksh^M: bad interpreter: No such file or directory
Sponsored Links
    #7  
Old 07-13-2010
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
Moderator
 
Join Date: Jan 2007
Last Activity: 20 September 2014, 5:20 AM EDT
Location: Варна, България / Milano, Italia
Posts: 5,674
Thanks: 182
Thanked 620 Times in 578 Posts
Yes,
with zsh:


Code:
print -l **/*(Dmh-1)

Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Find last modified date for many files MichaelH3947 UNIX for Dummies Questions & Answers 5 02-28-2010 10:48 AM
how to find the modified files before 60 mins? iamgeethuj UNIX for Dummies Questions & Answers 8 12-15-2008 06:31 AM
help: find and modified files script tarunicon Shell Programming and Scripting 6 10-10-2008 10:18 AM
find files modified more than a day karthikn7974 Shell Programming and Scripting 2 08-18-2008 06:07 AM
perl find directory only if modified in last hour frustrated1 Shell Programming and Scripting 0 10-12-2007 04:50 PM



All times are GMT -4. The time now is 11:57 AM.