I want to run a command on a very large folder to sort every item into subfolders based on modification date. Can this be done with one line?

I.e., all files modified in July 2013 would be moved to 2013-07 etc.

Something with find.... parse the year/month, then move to matching folder.

The man page for Mac's find is here: https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/find.1.html

1 Answer 1


I found the answer here ... and modified it for my needs:

for f in 12*; do   
     dir='/foo/bar/'$(stat -f%Sm -t%Y-%m "$f")
     [ -d "$dir" ] || mkdir "$dir"
     mv -nv "$f" "$dir"/

You can replace the m in -f%Sm with any of the following:

a, m, c, B

  • The time file was last accessed or modified, of when the inode was last changed, or the Birth time of the inode.

You must log in to answer this question.

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