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

  Unix/Linux 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 Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 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 Unix or Linux Image)

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

cheers
Sponsored Links
    #2  
Old Unix and Linux 07-13-2010
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
 
Join Date: Feb 2004
Last Activity: 30 March 2015, 8:53 PM EDT
Location: NM
Posts: 10,410
Thanks: 325
Thanked 854 Times in 793 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 Unix and Linux 07-13-2010
radoulov's Unix or Linux Image
radoulov radoulov is offline Forum Staff  
Moderator
 
Join Date: Jan 2007
Last Activity: 23 March 2015, 5:18 AM EDT
Location: Варна, България / Milano, Italia
Posts: 5,689
Thanks: 184
Thanked 623 Times in 581 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 Unix and Linux 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 Unix and Linux 07-13-2010
radoulov's Unix or Linux Image
radoulov radoulov is offline Forum Staff  
Moderator
 
Join Date: Jan 2007
Last Activity: 23 March 2015, 5:18 AM EDT
Location: Варна, България / Milano, Italia
Posts: 5,689
Thanks: 184
Thanked 623 Times in 581 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 Unix and Linux 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 Unix or Linux Image

---------- 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 Unix and Linux 07-13-2010
radoulov's Unix or Linux Image
radoulov radoulov is offline Forum Staff  
Moderator
 
Join Date: Jan 2007
Last Activity: 23 March 2015, 5:18 AM EDT
Location: Варна, България / Milano, Italia
Posts: 5,689
Thanks: 184
Thanked 623 Times in 581 Posts
Yes,
with zsh:


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

Sponsored Links
Closed Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Unix or Linux Image 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 04:27 AM.