LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
LinkBack Search this Thread
Old 04-18-2013, 11:06 PM   #1
sysmicuser
Member
 
Registered: Mar 2010
Posts: 246

Rep: Reputation: 0
Unhappy complex find?


Hi Guys,

I want find files in a directory and sub-directories which are in that directory for more than 3 hours but less than 24 , how to do?
 
Old 04-19-2013, 12:03 AM   #2
eklavya
Member
 
Registered: Mar 2013
Posts: 379

Rep: Reputation: 91
Try this.
Code:
find "/path/of/the/directory" -mmin -180 -mmin +1440
If you want to use between 2 to 4 days
Code:
find "/path/of/the/directory" -mtime -2 -mtime +4

Last edited by eklavya; 04-19-2013 at 12:06 AM.
 
Old 04-19-2013, 12:40 AM   #3
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5
Posts: 16,086

Rep: Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995
For exact times, you can use the -newerXY option eg http://stackoverflow.com/questions/1...-specific-date
 
Old 04-19-2013, 08:59 AM   #4
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 1,165

Rep: Reputation: 504Reputation: 504Reputation: 504Reputation: 504Reputation: 504Reputation: 504
Quote:
Originally Posted by eklavya View Post
Code:
find "/path/of/the/directory" -mmin -180 -mmin +1440
That will find files based on modification time, which might not be at all related to how long the files have had a link in a specified directory. Old files moved into a directory will retain their old mtime. Files that have been in that directory for a long time could have recent changes.

You could use ctime to detect old files that might have been recently moved into a directory, but all that is really telling you is how recently a change in file properties or hard links has occurred. There is no timestamp that will definitively reveal precisely what was asked, which is the list of files that were placed in a directory during a specified interval.
 
Old 04-20-2013, 04:40 AM   #5
sysmicuser
Member
 
Registered: Mar 2010
Posts: 246

Original Poster
Rep: Reputation: 0
@chrism01.

That is not what I a looking after. Not with a specific date but general search scenario where file was in a particular directory(or sub-directories) for more than 1hr(can be 2 hr or 3 hr) but is not older than 24 hours.
 
Old 04-20-2013, 04:54 AM   #6
sysmicuser
Member
 
Registered: Mar 2010
Posts: 246

Original Poster
Rep: Reputation: 0
@rknichols

Not sure why even mtime is not doing the trick, why the heck it should be that hard?
Code:
oracle@$ubuntu1210[/home/oracle]$ touch -t 201304192200 abcd.txt
-rw-rw-r--  1 oracle oinstall    0 Apr 19 22:00 abcd.txt
drwx------ 10 oracle oinstall 460K Apr 20 19:49 .
oracle@$ubuntu1210[/home/oracle]$ find . -mtime -60 -mtime +1440
Now with above find, we should have some result?

All we did in find was find in a that directory and sub-directories which has been there for more than an hr and less than 24 hrs. Simple and straightforward criteria.

Last edited by sysmicuser; 04-20-2013 at 04:55 AM.
 
Old 04-20-2013, 10:35 AM   #7
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 1,165

Rep: Reputation: 504Reputation: 504Reputation: 504Reputation: 504Reputation: 504Reputation: 504
Quote:
Originally Posted by sysmicuser View Post
Code:
oracle@$ubuntu1210[/home/oracle]$ find . -mtime -60 -mtime +1440
First, -mtime is in units of days, not minutes. Sorry about the confusion. When I referred to "mtime" and "ctime" I was talking about the names of the timestamps themselves (which are actually in units of seconds, or, for ext4, nanoseconds) and not the names of the find tests that examine them. And upon closer look, it is also rather difficult for mtime (in whatever units) to be both less than 60 and greater than 1440 simultaneously. Try:
Code:
find . -mmin +60 -mmin -1440
 
1 members found this post helpful.
Old 04-20-2013, 11:00 AM   #8
sysmicuser
Member
 
Registered: Mar 2010
Posts: 246

Original Poster
Rep: Reputation: 0
@rknichols

Thank you for making picture clear and enlightening that mtime is for "days" and not "hours". yes that what was I was looking for, precisely.
 
Old 04-21-2013, 08:43 PM   #9
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5
Posts: 16,086

Rep: Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995
newerXY allows you to specify the exact time as well as date; see last sentence here
Quote:
-newerXY reference
Compares the timestamp of the current file with reference. The reference argument is normally the name of a file (and one of its timestamps is used for the comparison) but it may also be a string describing an absolute time. X and Y are placeholders for other letters, and these letters select which time belonging to how reference is used for the comparison.
Some combinations are invalid; for example, it is invalid for X to be t. Some combinations are not implemented on all systems; for example B is not supported on all systems. If an invalid or unsupported combination of XY is specified, a fatal error results. Time specifications are interpreted as for the argument to the -d option of GNU date.
http://linux.die.net/man/1/find
 
1 members found this post helpful.
Old 04-22-2013, 06:18 AM   #10
sysmicuser
Member
 
Registered: Mar 2010
Posts: 246

Original Poster
Rep: Reputation: 0
@chrism01

Thanks mate.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Complex Find and Replace using sed or other tool marco114 Linux - Newbie 1 10-24-2011 05:42 PM
Complex routing axelgenus Linux - Networking 7 05-19-2010 12:28 PM
complex password sachin1361 Linux - Enterprise 2 04-01-2008 02:46 AM
complex find command ovince Programming 1 03-09-2007 05:46 PM
gsl_complex vs <complex> darknails Programming 0 02-27-2005 10:24 AM


All times are GMT -5. The time now is 08:30 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration