Invalid argument when running ‘find’ command with -exec and -mtime

execfindmtime

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?

Best Answer

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

Related Topic