1

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

0

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"/
done

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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