Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

How can I use find to select files that have been written and not modified in the last minute?

I know I can do it the other way around, find files modified in the last 60 seconds with -mtime -60s, but I want the ones that haven't been modified in the last 60 seconds.

I use Linux and get this error if I use seconds:

find ??/ -mtime +60s -name blah.tsv
find: invalid argument `+60s' to `-mtime'
share|improve this question
add comment

4 Answers

up vote 7 down vote accepted

Use find /path -mtime +60s

The - just before the digits is not a regular "argument dash", but means "less than". + then is "more than".

From man find:

All primaries which take a numeric argument allow the number to be preceded by a plus sign (``+'') or a minus sign (``-''). A preceding plus sign means ``more than n'', a preceding minus sign means ``less than n'' and neither means ``exactly n''.

It should be noted that for exactly n, the time is rounded. So 1 (1 day) does not mean 86400 seconds.

share|improve this answer
2  
Strictly speaking, +60 is not the opposite of -60, for the same reason less than is not the opposite of greater than: Both exclude the exact value they compare to. But your question does not indicate which behavior you want, exactly. –  Daniel Beck Jan 27 '12 at 16:56
    
This isn't exactly the same indeed, since ! reverts the original "query". But agreed, the OP doesn't specify what he wants. –  Karolos Jan 27 '12 at 17:02
    
The day after, the OP stated it is on Linux, not Mac OS X. If that would have changed the answer, can you update it? –  Peter Mortensen Sep 9 '12 at 12:43
    
Yeah, this doesn't work on Linux. At least RHEL 5.6. SiegeX's response below does work, however. –  khaki54 Jan 9 '13 at 19:07
    
@khaki54 Yeah, it's a bit confusing. While the user states that he uses Linux in an edit, he/she uses OS X/BSD find syntax in the second paragraph to the question ("I know I can do … with -mtime -60s") and has accepted this as the best answer... –  Daniel Beck Jan 9 '13 at 19:55
show 1 more comment

You should be able to use

find . ! -mtime -60s
share|improve this answer
1  
Requires parenthesis for me: find . !( -mtime -60s ) –  Oliver Salzburg Jan 27 '12 at 16:51
    
@OliverSalzburg: On my Mac, it works OK without the parenthesis (Darwin Kernel Version 11.2.0). –  Karolos Jan 27 '12 at 16:52
add comment

The second - in -mtime -60s is not an option delimiter.

-mtime is an option, and it is followed by an option argument. The option argument is -60s, and the - in it is part of the option argument itself, not an option delimiter. It means "less than 60 seconds". Option arguments 60s and +60s mean "equal to 60 seconds" and "greater than 60 seconds", respectively.

The Apple MacOS manual and the FreeBSD manual mention the + and - prefixes in exactly one place, and forget to explain anywhere what they are. This is what they are.

(The GNU Info manual for GNU find has the same omission, interestingly enough. However, GNU find's syntax for times is somewhat different to the BSD and MacOS find syntax.)

Further reading

  • Apple incorporated (2008-02-24). find MacOS 10 manual page. MacOS 10 Developer Library.
  • find(1). 2010-03-17. FreeBSD General Commands Manual. FreeBSD Project.
share|improve this answer
1  
It's even worse than just explaining it in exactly one place: All other options refer to atime for the time format, but that does also not explain the prefixes. It's a separate section that isn't referenced. –  Daniel Beck Jan 27 '12 at 16:59
    
Indeed; and you'll find that I wrote that. I wrote "mention", and "forget to explain anywhere". ☺ –  JdeBP Jan 27 '12 at 17:05
    
I didn't mean to contradict you, just wanted to point out that the exactly one place is also the worst possible place from a "let's just skim the man page" POV. –  Daniel Beck Jan 27 '12 at 17:07
    
But it isn't explained in exactly one place. It's not explained in any place at all. For a set of manual pages that is generally written and edited fairly well, in my experience, it's a surprising omission. –  JdeBP Jan 27 '12 at 17:28
1  
Heh! That's because you magically know the answer already and can connect the twain when reading the document, filling in what isn't actually written. The people who don't have (y)our foreknowledge and are reading the manual in order to find out have to wonder why there's no explanation of what a "modifier" is anywhere. ☺ –  JdeBP Jan 27 '12 at 18:11
show 1 more comment

Although you tagged this OSX, -mtime +60s is not portable. The following is, however:

find . -mmin +1

Example

$ ls *
four.txt  one.txt  three.txt  two.txt

$ touch foo && find . -mmin +1
.
./three.txt
./four.txt
./two.txt
./one.txt
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.