Find all files older than one minute

8

3

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'

719016

Posted 2012-01-27T16:26:44.980

Reputation: 2 899

Answers

13

Use find /path -type f -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.

Daniel Beck

Posted 2012-01-27T16:26:44.980

Reputation: 98 421

2Strictly 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 – 2012-01-27T16:56:14.027

This isn't exactly the same indeed, since ! reverts the original "query". But agreed, the OP doesn't specify what he wants. – Karolos – 2012-01-27T17:02:48.593

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 – 2012-09-09T12:43:25.800

1Yeah, this doesn't work on Linux. At least RHEL 5.6. SiegeX's response below does work, however. – MattPark – 2013-01-09T19:07:53.583

@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 – 2013-01-09T19:55:23.163

2This doesn't work on CentOS. As supposed it works in Mac OS X – trante – 2013-10-29T18:45:18.150

14

find . -type f -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

SiegeX

Posted 2012-01-27T16:26:44.980

Reputation: 1 911

It is no longer tagged with osx. – Peter Mortensen – 2017-11-26T17:49:09.323

4

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.

JdeBP

Posted 2012-01-27T16:26:44.980

Reputation: 23 855

1It'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 – 2012-01-27T16:59:01.293

Indeed; and you'll find that I wrote that. I wrote "mention", and "forget to explain anywhere". ☺ – JdeBP – 2012-01-27T17:05:35.713

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 – 2012-01-27T17:07:39.313

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 – 2012-01-27T17:28:59.660

See my answer. There is actually a place where it's explained (unfortunately in very abstract terms), but it's not part of the atime explanation or referenced there. – Daniel Beck – 2012-01-27T17:41:43.827

1Heh! 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 – 2012-01-27T18:11:30.123

3

You should be able to use

find . ! -mtime -60s

Karolos

Posted 2012-01-27T16:26:44.980

Reputation: 2 304

1Requires parenthesis for me: find . !( -mtime -60s ) – Der Hochstapler – 2012-01-27T16:51:13.113

@OliverSalzburg: On my Mac, it works OK without the parenthesis (Darwin Kernel Version 11.2.0). – Karolos – 2012-01-27T16:52:05.003

1

In Unix systems -mtime used to be followed by a +/- followed by a number followed by units of time. [+-]nn[dms]

Linux uses mtime for days, mmin for minutes, but there doesn't seem to be a seconds option and doesn't use a time units specifier. The + or - still refers to greater than or less than the time rather than be a option argument as mentioned above.

You could use -mmin 1, but https://unix.stackexchange.com/questions/238738/find-files-newer-than-15-seconds-but-older-than-2-seconds discusses how to handle seconds in general.

Nick Greenwood

Posted 2012-01-27T16:26:44.980

Reputation: 11