Find files modified in last hour sunOS 5.10


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find files modified in last hour sunOS 5.10
# 8  
Old 07-13-2010
Quote:
Originally Posted by radoulov
Yes,
with zsh:

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

Thanks Smilie I guess it's not that easy with ksh then
# 9  
Old 07-13-2010
I suppose it is not, I would use Perl Smilie
# 10  
Old 07-13-2010
I don't understand how to integrate your perl code into a shell script rad, can you give an example? i.e. switching to the directory /richard/share then listing all files in there modified in the last hour?
# 11  
Old 07-13-2010
If that's the only operation, you could simply execute this code on your command line:

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

If you need to include that code in a script, just paste it inside:

Code:
#!/bin/sh
... other code here ...
filenames="$(
  perl -MFile::Find -le'
  find { 
    wanted => sub {
      -f and 1 / 24 >= -M and print $File::Find::name;
      }
    }, shift    
  ' /richard/share  
)"
... continue here ...


Last edited by radoulov; 07-13-2010 at 02:41 PM.. Reason: corrected
# 12  
Old 07-13-2010
is this line here:

Code:
-f and 1

which does the actual test to see if it's less than 1 hour? I take it the 1 relates to 1 hour?

when i run it against my directory it shows files which have been modified over an hour ago?

Code:
function SearchLogsLastHour
{

cd $URS_LOGS

filenames="$(
  perl -MFile::Find -le'
  find { 
    wanted => sub {
      -f and 1 >= -M and print $File::Find::name;
      }
    }, shift    
  ' /export/home/richard/share/ipcc/urslogs  
)"

echo $filenames | ls -l

}

When i run the above it just shows all the file in the directory - I opened and saved one of them, ran it again (expected it to just list the one file I saved a few seconds ago) but it still lists all the files the directory

Last edited by rich@ardz; 07-13-2010 at 01:23 PM.. Reason: additional info
# 13  
Old 07-13-2010
Sorry, 1 is one day, so you need 1/24:

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


I corrected my posts above.

Last edited by radoulov; 07-13-2010 at 02:40 PM..
This User Gave Thanks to radoulov For This Post:
# 14  
Old 07-13-2010
Working Smilie cheers for that rad; you the man Smilie

---------- Post updated at 08:11 PM ---------- Previous update was at 07:25 PM ----------

so say the perl program finds 3 files matching the critera - is there an easy way to modify this so that once the first file is found, we do a grep on that file then output what we need to the temp file, then proceed to the second file, do a grep on that, output to the temp file etc etc?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Command to find files older than 1 hour

Hi, Out of a list of files in a directory, I want to find the files which were created/modified more than 1 hour ago. I am using HP -UNIX and it does not support the argument -mmin. Please advise. I am using # !/bin/sh (4 Replies)
Discussion started by: jhilmil
4 Replies

2. UNIX for Advanced & Expert Users

Find files modified in previous minute only

Hi, How can I get files which are modified only in last minute ? it should not display 2 minutes back filels -la -rw-rw-r-- 1 stuser st 51 Dec 3 09:22 a.csv -rw-rw-r-- 1 stiser st 50 Dec 3 09:25 b.csv -rw-rw-r-- 1 stuser st 53 Dec 3 09:33 c.csv When I run command at 9:34am then I... (7 Replies)
Discussion started by: sbjv
7 Replies

3. Shell Programming and Scripting

How to find the files created within one hour in Solaris?

Hi Gurus, I want to find the file created within one hour in solaris. I have tried below command, but it is no lucky. $find . -mtime -1/24, -name "abc*" above command give me the file name which created two hours ago find . -cmin -60, -name "abc*" above command I got error as... (4 Replies)
Discussion started by: ken6503
4 Replies

4. Shell Programming and Scripting

List last 1 hour files with out FIND command

Hi Friends, Can we have an alternate command to list last 1hour files with out FIND command? Thanks Suresh (6 Replies)
Discussion started by: suresh3566
6 Replies

5. UNIX for Dummies Questions & Answers

HP UNIX: How to find files which are older than one hour.

HP Unix Version: HP-UX B.11.31 U ia64 Question I look for script or command to find files which are older than one hour. Tried below; # set the file time to 1 hours ago touch -t 201307160700 ./touchfile find /app/grid/product/11.2.0.3/rdbms/audit -name '*.aud' -type f ! -newer... (4 Replies)
Discussion started by: Siva SQL
4 Replies

6. UNIX for Dummies Questions & Answers

Find last modified date for many files

Hello all - I've looked and have not been able to find a "find" command that will list the last modified date of files within a specific directory and its subdirectories. If anyone knows of such a command it would be very much appreciated! If possible, I would like to sort this output and have... (5 Replies)
Discussion started by: MichaelH3947
5 Replies

7. UNIX for Dummies Questions & Answers

how to find the modified files before 60 mins?

hi, I need to find all the modified files before 60 minutes in a folder. Is that possible to find using mtime in minutes? Suggestions please. Thanks for looking into it... Geetha (8 Replies)
Discussion started by: iamgeethuj
8 Replies

8. Shell Programming and Scripting

help: find and modified files script

hello all im a newbie in the linux world ..i have just started creating basic scripts in linux ..i am using rhel 5 ..the thing is i wanted to create a find script where i could find the last modified file and directory in the directory given as input by the user and storing the output in a file so... (6 Replies)
Discussion started by: tarunicon
6 Replies

9. Shell Programming and Scripting

find files modified more than a day

Hi All, I am using the below command to check the files modified within last 24hours find /home/karthik -mtime -1 -type f -exec ls -l {} \; What parameter do i need to add in the above command to check the files modified in last 2 or 3 days Kindly let me know if any other alternative... (2 Replies)
Discussion started by: karthikn7974
2 Replies

10. Shell Programming and Scripting

perl find directory only if modified in last hour

I want a one liner perl command to find a directory only if the modified time is within the last hour I am running this on windows - and I will define a variable for the result. So for example I want to return value of 1 for the variable if the modified time of d:\test1 is within the last... (0 Replies)
Discussion started by: frustrated1
0 Replies
Login or Register to Ask a Question