Help with archiving using find

Dear Unix Experts,

I am trying to backup some legacy data based on date. I am pasting a small portion from the ls -al command from my session for reference.

athena>ls -al

./nmr/exam1d_13C:
total 32
drwxrwxrwx    3 root     root         4096 May  1  2008 1/
drwxrwxrwx    3 root     root         4096 Apr 11  2008 2/
drwxrwxrwx   14 root     root         4096 Jan 22  2008 ../
drwxrwxrwx    3 root     root         4096 Jan 13  2005 6/
drwxrwxrwx    3 root     root         4096 Jan 13  2005 5/
drwxrwxrwx    8 root     root         4096 Mar 30  2004 ./

./nmr/exam2d_HC:
total 24
drwxrwxrwx    3 root     root         4096 Apr 11  2008 1/
drwxrwxrwx    3 root     root         4096 Dec 21  2004 4/
drwxrwxrwx   14 root     root         4096 Jan 22  2008 ../
drwxrwxrwx    6 root     root         4096 Mar 30  2004 ./

I am trying to archive these files based on the year like below. Just to complicate things a little bit more, I expect to see sub-directories like 1/ 2/ and so on. under ./nmr/exam1d_13C/1 etc.

./nmr/exam1d_13C/1 to /archive/2008/nmr/exam1d_13C/1
./nmr/exam1d_13C/2 to /archive/2008/nmr/exam1d_13C/2
./nmr/exam1d_13C/5 to /archive/2005/nmr/exam1d_13C/5
./nmr/exam1d_13C/6 to /archive/2005/nmr/exam1d_13C/6
./nmr/exam2d_HC/1 to /archive/2008/nmr/exam2d_HC/1
./nmr/exam2d_HC/4 to /archive/2008/nmr/exam2d_HC/4

I am stuck. I tried using find, but with no success. I would appreciate any help.

Thanks
Jaison

Next time use CODE-tags when posting code, data or logs to enhance readability and keep formatting like indention etc., ty.

Finding a list of old files is usually done with something like:

# find . -type f -mtime +365

This would list all files in or under the current directory that have not been modified in the last year.

You could move all files older than a year like so:

# find . -type f -mtime +365 -exec mv {} /archive \;

This would not preserve the directory structure.

You could do something like this to preserve the directory structure:

# find . -type f -mtime +365 | awk '{ print "mv "$1" /archive/"$1 }' | sed 's/\/\.\//\//' > /tmp/moveoldfiles.sh

check that /tmp/moveoldfiles.sh will do what you intended and then run it.

HTH?

HTH?