Matt
Matt

Reputation: 357

Copy everything is single folder from x months back

How do I copy every file in one folder without copying the sub folder contents. The sub folder contents are overwriting the parent files (same names)

-images
  .image1.png
  ..
  -thumbs
    .image1.png

I have tried find . -mtime -120 -exec cp {} /dest/images \; sub folder thumbs contents overwrite the current files in current folder.

find . -mtime -120 -exec cp {} /images \;

Upvotes: 0

Views: 44

Answers (2)

wjandrea
wjandrea

Reputation: 33145

Use -maxdepth 2:

find . -maxdepth 2 -mtime -120 -exec cp {} /images \;

From man find:

   -maxdepth levels
          Descend at most levels (a non-negative integer) levels of
          directories below the starting-points.  -maxdepth 0 means only
          apply the tests and actions to the starting-points themselves.

Upvotes: 1

jeremysprofile
jeremysprofile

Reputation: 11464

If your goal is just to omit the subfolders' contents, you can specify a certain depth to use:

find . -maxdepth 1 -mtime -120 -exec cp {} /images \;

This will ignore everything that isn't in the current folder. There's also -mindepth, which is fairly self-explanatory.

Upvotes: 2

Related Questions