unix find command without mmin option


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting unix find command without mmin option
# 1  
Old 06-04-2009
unix find command without mmin option

I need to check if a file has been modified within the last x hours. My find command does not have the mmin option -- only the mtime option which is in 24 hour perriods
# 2  
Old 06-04-2009
Quote:
Originally Posted by Bill Ma
I need to check if a file has been modified within the last x hours. My find command does not have the mmin option -- only the mtime option which is in 24 hour perriods
One way to do it:

Code:
$
$
$ touch --date="1-Jan-2009 10:11:12 AM" file1
$
$ touch file2
$
$ cat filetime.pl
#!perl
#
# Usage: perl filetime.pl <file_name> <age_in_hours_0_to_23>
#
use Date::Calc;
$file=$ARGV[0];
$age=$ARGV[1];
# file modification time
$mtime = (stat($file))[9];
($s1, $min1, $h1, $d1, $mon1, $y1) = (localtime($mtime))[0,1,2,3,4,5];
$mon1++;
$y1 += 1900;
# current time
($s2, $min2, $h2, $d2, $mon2, $y2) = (localtime)[0,1,2,3,4,5];
$mon2++;
$y2 += 1900;
($Dd,$Dh,$Dm,$Ds) = Date::Calc::Delta_DHMS($y1,$mon1,$d1, $h1,$min1,$s1,
                                           $y2,$mon2,$d2, $h2,$min2,$s2);
if ($Dd > 0 or $Dh >= $age) {
  print "The file: $file is at least $age hours old.\n"
} else {
  print "The file: $file is less than $age hours old.\n"
}
$
$ perl filetime.pl file1 10
The file: file1 is at least 10 hours old.
$
$ perl filetime.pl file2 10
The file: file2 is less than 10 hours old.
$

Hope that helps,
tyler_durden
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 mmin

Hi, Please tell me what the below command wil do, according to my understanding it finds files in the current and sub directories whose modification time is 5 hrs and it dont zip the already zipped files who's size is more than 4K. Am I Correct? find . -type f -mmin +300 ! -name... (1 Reply)
Discussion started by: nag_sathi
1 Replies

2. Shell Programming and Scripting

Unix Find with exec option.

All, I am using following find command to see all the files with specified pattern : find /exp/source -exec grep -li "SIT_MARKET" {} \; say , the /exp/source has n number of subdirectories and each subdirectory has its own directory tree. If this is the case I will get a result... (9 Replies)
Discussion started by: kanu_kanu
9 Replies

3. Shell Programming and Scripting

Confusing find command option

Hi, I am a little bit confusing of using find command. Actually, I am planning to delete the files whatever the files are existing in the day before yesterday. So, I am writing the command like this. find . -name "*.txt" -ctime -2 { here I am confusing, if I will use +2 or +1 also I am... (5 Replies)
Discussion started by: nagraju.allam
5 Replies

4. Shell Programming and Scripting

Please suggest me a better option than FIND command

Hi All, Could you please help me in searching files in a better way satisfying the below conditions I want to search files in a path whose access time is more than 5min and less than 60 min and whose Byte size is greater than zero For this, i am using the below command, but it is... (2 Replies)
Discussion started by: sparks
2 Replies

5. Shell Programming and Scripting

help with find command and prune option

Hi I have a directory say mydir and inside it there are many files and subdirectories and also a directory called lost+found owned by root user I want to print all files directories and subdirectorres from my directory using find command except lost+found If i do find . \( -name... (3 Replies)
Discussion started by: xiamin
3 Replies

6. UNIX for Dummies Questions & Answers

help me out with find command , -prune option

Hi , Kindly help me out .:) i want to find only the file t4 in directory t3. i am in dir t . the tree is as follows. if i give, find . o/p is . ./t4 ./t1 ./t1/t2 ./t1/t2/t3 ./t1/t2/t3/t4 ./t1/t2/t4 ./t1/t4 directories are like t/t1/t2/t3 and each directory has file t4. my... (7 Replies)
Discussion started by: bhuvaneshlal
7 Replies

7. Solaris

Any alternative of find . -mmin 20

hi find command is not working with -mmin in Solaris Os. Do we hav any alternative to find the modified file in any specified time span ( suppose in last 1- 2 hours) Thanks (2 Replies)
Discussion started by: Prat007
2 Replies

8. UNIX for Dummies Questions & Answers

Unix command mmin issue

hi, Function 'mmin' is not in my unix, what is the other alternative to find files created/modified in last 10 minutes. Unix Command: find . -min -10 find: bad option -min find: path-list predicate-list Thank you (1 Reply)
Discussion started by: Mohee
1 Replies

9. HP-UX

find command using -mmin param

Hi Everyone, I would like to know how to find a file which was created in the period of 20+ hours, in most common unix OS, the parameter -mmin is not supported (i.e, HP-UX, Solaris, LInux, AIX) Could you help on this ?? (3 Replies)
Discussion started by: jmbeltran
3 Replies

10. UNIX for Dummies Questions & Answers

no [find -mmin -1]

I wanna show all files like...one minute old, one hour old, five hours old and so on... in my OS (HP-UX) there's only the command .. find -name "..." -mtime -n but this is only for days, there isn't something like -mmin -n ...just don't know what to do. also the newer than option isn't... (3 Replies)
Discussion started by: svennie
3 Replies
Login or Register to Ask a Question