2

Pretty wierd error message came up on Centos.

I tried to run this command:

find /tmp/something -type f -mtime +2h -exec cp '{}' /tmp/target \;

And the error I've got:

find: invalid argument `-exec' to `-mtime'

Can the 'find' be different on other distributions?

t.fazakas
  • 61
  • 1
  • 1
  • 6

2 Answers2

5

-mtime is used for days, if you need 2 hours check this:

find /tmp/something -type f -mmin +120 -exec cp '{}' /tmp/target \;

mmin specifies minutes so -mmin +120 will filter those more than 120 minutes ago (2 hours). From the manual:

-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.

-mmin n

File's data was last modified n minutes ago.

alphamikevictor
  • 1,062
  • 6
  • 19
1

the find implementation on MacOS is a little bit different than the one available on Linux. I believe you got the error above on a Linux system.

On Linux, mtime only accepts +- and a number. The number is the number of days.

For what you want to do above you have to use mmin

-mmin n
      File’s data was last modified n minutes ago.

This command should work on Linux:

find /tmp/something -type f -mmin +120 -exec cp '{}' /tmp/target \;
Luis
  • 306
  • 1
  • 2
  • 10