Search code examples
bashdatecopymove

Copy/move all files which last modified date are in a given month


I have a question about terminal command. At work, we receive in a folder many files everyday. Today we decide to organize this full amount of files collecting them in folders using year and month as a rule.

Question, how can i move all the files which last modified date are in the range of the month of April of 2013, for example.


Solution

  • You can easily select files whose modification times are in a time range with the find command. Here's an example with gnu find, which makes this fairly simple:

    find . -newermt 'Apr 1, 2013 00:00' -not -newermt 'May 1, 2013 00:00' \
           -exec mv -t /path/to/April_2013/directory '{}' '+'
    

    man find for all the gory details.