The solution with mtime specifying seconds doesn't work on my linux systems that use find --version
== find (GNU findutils) 4.4.2
.
I get the following error:
mycomputer:~/new$ find . -mtime -60s
find: missing argument to `-mtime'
mycomputer:~/new$ find . -mtime -60seconds
find: missing argument to `-mtime'
However, I can use -mmin
(for modified in the last m minutes), and can it can take in a decimal argument; e.g., the following finds files modified in the last 30 seconds.
find . -mmin 0.5
So for example; creating files last modified 1s, 6s, 11s, ... ago for the past 120 seconds, this command finds:
mycomputer:~/new$ for i in $(seq 1 5 120); do touch -d "-$i seconds" last_modified_${i}_seconds_ago ; done
mycomputer:~/new$ find . -mmin 0.5
.
./last_modified_1_seconds_ago
./last_modified_26_seconds_ago
./last_modified_11_seconds_ago
./last_modified_16_seconds_ago
./last_modified_21_seconds_ago
./last_modified_6_seconds_ago
So if you really need it in seconds you can do something like:
localhost:~/new$ for i in $(seq 1 1 120); do touch -d "-$i seconds" last_modified_${i}_seconds_ago ; done
localhost:~/new$ N=18; find . -mmin $(echo "$N/60"|bc -l)
./last_modified_1_seconds_ago
./last_modified_9_seconds_ago
./last_modified_14_seconds_ago
./last_modified_4_seconds_ago
./last_modified_12_seconds_ago
./last_modified_13_seconds_ago
./last_modified_8_seconds_ago
./last_modified_3_seconds_ago
./last_modified_5_seconds_ago
./last_modified_11_seconds_ago
./last_modified_17_seconds_ago
./last_modified_16_seconds_ago
./last_modified_7_seconds_ago
./last_modified_15_seconds_ago
./last_modified_10_seconds_ago
./last_modified_6_seconds_ago
./last_modified_2_seconds_ago
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.
Best Answer
To find files modified at least 5 days in the future, use:
The syntax for the time specification corresponds to the one for
date -d
. Seeman find
for info on the switch named-newerXY
for more information.It is not possible to use e.g.
-mmin
to do this. It was reported as a bug against GNU find, and was solved by implementing-newerXY
in findutils 4.3.3 (~2007) as I showed above.Apparently it was not GNU find that was used, but BusyBox.
You should then be able to create a temporary file with
touch -d
and a date in the future and then use the-newer
switch forfind
such as:BusyBox
touch
does not support that date format, but the principle is the same and itsfind
supports-newer
. Creating the reference file with a correct date is left as an exercise for the reader (always convenient to write).