LinuxQuestions.org
Help answer threads with 0 replies.
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
  Search this Thread
Old 02-05-2013, 10:29 AM   #1
ashley75
Member
 
Registered: Aug 2003
Posts: 232

Rep: Reputation: 30
find with -mtime doesn't work


if I run

$find /usr/oracle/logs/ -type f

I can see lots of files in there, and if I run

$find /usr/oracle/logs/ -type f -mtime +2

nothing is returned, basically I want to find any files that are older than 2 days.

thx
 
Old 02-05-2013, 11:15 AM   #2
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,604

Rep: Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241
sounds like none of the files are that old...
 
Old 02-05-2013, 12:14 PM   #3
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
Can you try:
Code:
~$ find /usr/oracle/logs/ -type f -mtime -2
OR
~$ find /usr/oracle/logs/ -type f -mtime -2 -print
In your case, may be no file was modified in /usr/oracle/logs/. I am not sure, but just a tip.

Last edited by shivaa; 02-05-2013 at 12:16 PM.
 
Old 02-05-2013, 09:24 PM   #4
lleb
Senior Member
 
Registered: Dec 2005
Location: Florida
Distribution: CentOS/Fedora
Posts: 2,630

Rep: Reputation: 495Reputation: 495Reputation: 495Reputation: 495Reputation: 495
or:

Code:
find /usr/oracle/logs -mtime +2 -exec ls -laF '{}' \;
from the man page for find:

Quote:
-mtime n
File's data was last modified n*24 hours ago. See the comments for -atime to understand how rounding affects the interpretation of file modification times.
in other words you can not have a negative time, you have to have a positive time, so try with + instead of -. should work for you.
 
Old 02-06-2013, 01:19 AM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,241

Rep: Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325
Under the section TESTS, which includes eg -mtime
Code:
Numeric arguments can be specified as
+n

for greater than n,

-n

for less than n,

n

for exactly n.
http://linux.die.net/man/1/find
 
1 members found this post helpful.
Old 02-06-2013, 08:23 AM   #6
lleb
Senior Member
 
Registered: Dec 2005
Location: Florida
Distribution: CentOS/Fedora
Posts: 2,630

Rep: Reputation: 495Reputation: 495Reputation: 495Reputation: 495Reputation: 495
good to know, but a -2 with mtime will not locate a file that is older then 48hrs, it would be looking for a file that is 22hrs according to that info. so in the OPs case using -2 will not generate the results he is looking for.

correct?
 
Old 02-06-2013, 08:44 AM   #7
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
Quote:
Originally Posted by lleb View Post
good to know, but a -2 with mtime will not locate a file that is older then 48hrs, it would be looking for a file that is 22hrs according to that info. so in the OPs case using -2 will not generate the results he is looking for.

correct?
Not correct. As per manual of find:
Quote:
-mtime n
File's data was last modified n*24 hours ago.
So adding a -2 with -mtime option means -2x24 hours i.e. -48 hours. So it will look for files modified in last 48 hours from the moment command was fired. I am quite sure about this explaination.
 
Old 02-06-2013, 04:01 PM   #8
lleb
Senior Member
 
Registered: Dec 2005
Location: Florida
Distribution: CentOS/Fedora
Posts: 2,630

Rep: Reputation: 495Reputation: 495Reputation: 495Reputation: 495Reputation: 495
interesting as i get the same, 48hr, results with a +2 on my mtime find.
 
Old 02-06-2013, 06:22 PM   #9
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,241

Rep: Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325
Actually, this might help also
Quote:
-daystart
Measure times (for -amin, -atime, -cmin, -ctime, -mmin, and -mtime) from the beginning of today rather than from 24 hours ago. This option only affects tests which appear later on the command line.
from the same page
 
Old 02-06-2013, 06:59 PM   #10
jv2112
Member
 
Registered: Jan 2009
Location: New England
Distribution: Arch Linux
Posts: 719

Rep: Reputation: 103Reputation: 103
Question

It has always been my experience that -mtime -n is within n days. Strange



Code:
[-joe@Flying-Kernel-] 
|- in [~]-|-> find . -type f -and -mtime -2 -exec ls -lt {} +
-rw-r--r-- 1 joe arch   669090 Feb  6 18:55 ./.mozilla/firefox/62ot7um5.default/safebrowsing/goog-phish-shavar.pset
-rw-r--r-- 1 joe arch      684 Feb  6 18:55 ./.mozilla/firefox/62ot7um5.default/safebrowsing/goog-phish-shavar.cache
-rw-r--r-- 1 joe arch   629473 Feb  6 18:55 ./.mozilla/firefox/62ot7um5.default/safebrowsing/goog-phish-shavar.sbstore
-rw------- 1 joe arch    33464 Feb  6 18:55 ./.bash_history
-rw-r--r-- 1 joe arch   807272 Feb  6 18:55 ./.mozilla/firefox/62ot7um5.default/safebrowsing/goog-malware-shavar.pset
-rw-r--r-- 1 joe arch      844 Feb  6 18:55 ./.mozilla/firefox/62ot7um5.default/safebrowsing/goog-malware-shavar.cache
-rw-r--r-- 1 joe arch  1673959 Feb  6 18:55 ./.mozilla/firefox/62ot7um5.default/safebrowsing/goog-malware-shavar.sbstore
-rw-r--r-- 1 joe arch       16 Feb  6 18:55 ./.mozilla/firefox/62ot7um5.default/safebrowsing/test-phish-simple.pset
-rw-r--r-- 1 joe arch        4 Feb  6 18:55 ./.mozilla/firefox/62ot7um5.default/safebrowsing/classifier.hashkey
 
Old 02-06-2013, 07:18 PM   #11
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
There's a minor difference between results produced by +n and -n argument with -mtime option. I found that man pages do not have this explaination, so as per this:-

Quote:
-mtime +60 means you are looking for a file modified 60 days ago.
-mtime -60 means less than 60 days.
-mtime 60 If you skip + or - it means exactly 60 days.
So its better to use -n than +n.

Last edited by shivaa; 02-06-2013 at 08:42 PM. Reason: Typo rectified
 
1 members found this post helpful.
Old 02-06-2013, 07:31 PM   #12
lleb
Senior Member
 
Registered: Dec 2005
Location: Florida
Distribution: CentOS/Fedora
Posts: 2,630

Rep: Reputation: 495Reputation: 495Reputation: 495Reputation: 495Reputation: 495
Quote:
Originally Posted by shivaa View Post
There's a miner different between results produced by +n and -n argument with -mtime option. I found that man pages do not have this explaination, so as per this:-



So its better to use -n than +n.
Thank you shivaa, that helps a bunch.
 
Old 02-06-2013, 08:05 PM   #13
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,241

Rep: Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325
@Shivaa; my post #5 said that
 
1 members found this post helpful.
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
find -mtime gives unexpected results amchargue Linux - Newbie 3 08-12-2010 05:19 PM
[SOLVED] Command to find only mtime ddenton Linux - General 3 08-12-2010 03:57 PM
mtime option in find command ahmedb72 Linux - Newbie 7 06-23-2009 10:48 AM
using find to compare file mtime with another file's mtime TheFueley Linux - Newbie 1 12-23-2008 09:06 PM
mtime in find vs ls lslade Linux - Software 0 11-17-2005 02:06 PM


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

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration