I'm trying to make a zip file of all the files in a specific directory which were modified in the last x minutes.

Here's my command:

find "/path/to/dir" -mmin -30 -not -name ".*" -exec zip -r "testfile.zip" "{}" \+

If I make the modify time small enough, then it correctly identifies the one file that I recently changed.

The problem is... if I increase the minimum modify time to, say, 50 (it keeps changing), then the zip file adds all of the files in /path/to/dir. Even though all the files were definitely not changed.

So somehow, there is a specific file that is causing the whole find command to blow up. I looked through all the recently modified files (within last day) for a file with spaces in it or something, but I didn't find any. And it shouldn't matter, since I'm quoting the braces, right?

What else could be causing this weird behavior?

  • 2
    Was the directory recently modified? Try putting -not -type d in there so that find won't match the directory itself. Dec 2, 2014 at 18:41

1 Answer 1


By default, find includes everything in its search: directories, files, and symlinks.

find "/path/to/dir" -mmin -30 -not -name ".*" -exec zip -r "testfile.zip" "{}" \+

If /path/to/dir was modified in the last 30 minutes, it will pass all the tests, and zip, since it was given the -r option, will add the directory and everything under it to the archive.

You can approach this in a few ways, using either (or both) of the following:

  • Don't give zip the -r option. You're only interested in recently-modified files rather than every file that is in a recently-modified directory.
  • Add the -not -type d test to the find expression, so that it doesn't match directories.
find "/path/to/dir" -not -type d -mmin -30 -not -name ".*" -exec zip "testfile.zip" "{}" \+
  • Thanks again - leaving out the '-r' turned out to be the better option. I didn't realize that the files would still retain their parent folder structure with that option turned off. Dec 2, 2014 at 19:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .