I wish to know a command I can use to grab and archive all files for a year at a time. I am working on a directory that has 72000 files, with files dated from 2007 to current. And I wish to make that more manageable by tar-bziping older files in one-year groups. Thus, all files from 1-1-2007 to 12-31-2007, etc. Thanks for the help!
cd /path/to/directory find -type f -newermt 2007-01-01 ! -newermt 2008-01-01
Note that this selects files created in 2007 in your time zone, and files timestamped exactly at midnight on year change are grouped with the preceding year.
If your version of CentOS has an old version of
find that doesn't support
-newermt, you can use
-newer with fencepost files instead.
touch -d 2007-01-01 /tmp/2007-01-01 touch -d 2008-01-01 /tmp/2008-01-01 find -type f -newer /tmp/2007-01-01 ! -newer /tmp/2008-01-01
Assuming that the file names don't contain newlines, you can pipe the resulting listing as input for
tar with the
-T option (
-T - means to read file names from standard input).
cd /path/to/directory find -type f -newermt 2007-01-01 ! -newermt 2008-01-01 | tar -cjf /elsewhere/2007.tar.bz2 -T -
tar -cJf /elsewhere/2007.tar.xz instead, xz is faster to decompress and compresses better, at the expense of requiring more memory when compressing.)