I would like to copy all the files created in the last 12 months to a new folder leaving behind everything else. Including sub folders.

  • Strictly speaking, this is almost impossible; most *nix systems don't keep track of files' creation date/times.  You can, however, look at when they were last changed or modified. Apr 23 '15 at 3:13
  • By “including sub folders”, do you mean that they should be copied, that files in them should be copied, or that they should be left behind? Apr 24 '15 at 4:53

assuming you are ok with a flat destination folder (everything moved to the same place):

find /<top_level_folder> -type f -ctime -365 -exec cp -f {} /<new_folder_destination> \;
  • To get all files changed in the past year, use -ctime -365 (or perhaps -366). Apr 23 '15 at 3:15
  • Updated. Thanks for catching my typo!
    – Chad Smith
    Apr 23 '15 at 3:21
  • You could also use -mtime instead of -ctime to get all files modified in the last year
    – Chad Smith
    Apr 23 '15 at 3:36
  • Well, yes; as I (somewhat obscurely) point out in a comment on the question, there are two different ways of interpreting the question.  They are not equivalent. Apr 23 '15 at 3:39
  • 1
    This question probably calls for -mtime, not -ctime. All kinds of things can change the ctime, such as changing permissions. If you want to find files created or modified in a certain date range, then the mtime is exactly right, under the reasonable assumption that it was not deliberately modified. Apr 24 '15 at 4:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.