LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-06-2013, 04:45 PM   #1
valaji123
LQ Newbie
 
Registered: Oct 2013
Posts: 2

Rep: Reputation: Disabled
Linux/Perl Returning list of folders that have not been modified for over x minutes


I have a directory that has multiple folders. I want to get a list of the names of folders that have not been modified in the last 60 minutes.
The folders will have multiple files that will remain old so I can't use -mmin +60.

I was thinking I could do something with inverse though. Get a list of files that have been modified in 60 minutes -mmin -60 and then output the inverse of this list.

Not sure to go about doing that or if there is a simpler way to do so?


This is what I have so far to get the list of folders

'find /path/to/file -mmin -60 | sed 's/\/path\/to\/file\///' | cut -d "/" -f1 | uniq'

Above will give me just the names of the folders that have been updated.
 
Old 11-06-2013, 09:22 PM   #2
MisterBark
Member
 
Registered: Jul 2012
Location: Republic of Krakozhia
Distribution: Slackware & Zenwalk core + compile
Posts: 104

Rep: Reputation: 6
Code:
find /path/containing/directories -type d -exec perl -e 'my $d=$ARGV[0]; exit if (stat($d))[9] > time-600; $d =~ s!^/path/containing/directories/!!; print("$d\n");' '{}' \;

Last edited by MisterBark; 11-06-2013 at 09:49 PM.
 
Old 11-07-2013, 05:15 PM   #3
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by valaji123 View Post
I have a directory that has multiple folders. I want to get a list of the names of folders that have not been modified in the last 60 minutes.
The folders will have multiple files that will remain old so I can't use -mmin +60.

I was thinking I could do something with inverse though. Get a list of files that have been modified in 60 minutes -mmin -60 and then output the inverse of this list.

Not sure to go about doing that or if there is a simpler way to do so?


This is what I have so far to get the list of folders

'find /path/to/file -mmin -60 | sed 's/\/path\/to\/file\///' | cut -d "/" -f1 | uniq'

Above will give me just the names of the folders that have been updated.
Well, if you want a pure Perl (no 'system') solution, I suggest to read:

http://perldoc.perl.org/functions/opendir.html ,
http://perldoc.perl.org/functions/readdir.html ,
http://perldoc.perl.org/functions/closedir.html ,
http://perldoc.perl.org/filetest.html ,
http://perldoc.perl.org/functions/stat.html .

And after that http://datetime.perl.org/wiki/datetime/dashboard and find there how to calculate time intervals.

By the way, there is general pitfall of daylight saving time <-> regular time - regardless of language and OS.
 
  


Reply

Tags
find, linux, perl



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Finding files modified n minutes ago tucs_123 AIX 5 10-09-2009 12:59 AM
Perl DBI: $dbh->do, returning primary key of those modified snoopy1 Linux - Software 0 05-25-2009 05:23 AM
Find out if a file was modified in the last 2 minutes.... cricos Programming 5 04-06-2005 02:57 PM
The 'modified times' of files and folders is reset when copied from windows to linux? crazyswede Linux - Newbie 7 03-02-2004 08:53 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:14 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration