Move files from one location to another

Hi,

I wanted to check how to move files from one location to another based some particular date.

Example I want to move /data/NewJersey folder to /home/scripts/NJ ( including all the files and subfolders within it ), but only which are older than say 8th February 2010.

script , awk, sed ( doesn't matter)

Thanks

Not quite what you are asking but nearly.
If the 28th Feb. was 33 days ago then:

find /data/NewJersey -type f -mtime +33 -exec mv {} /home/scripts/NJ ;/

You could give this a try?

The version of Unix determines what options you have available to the find(1) command, so what version of Unix are you using?

I am using

Linux 2.6.9-34.ELsmp #1 SMP Fri Feb 24 16:56:28 EST 2006 x86_64 x86_64 x86_64 GNU/Linux

---------- Post updated at 05:33 PM ---------- Previous update was at 05:28 PM ----------

Get an error

find: missing argument to `-exec'
-bash: /: is a directory

---------- Post updated at 05:38 PM ---------- Previous update was at 05:33 PM ----------

Command works with a slight modification like below, but doesn't create the same directory structure as at the source

find /data/NewJersey -type f -mtime +33 -exec mv {} /home/scripts/NJ \;

Agreed, sorry got the "\;" at the end from memory wrong!

This turned out to be quite complex and interesting . Please test on expendable data.
My proposed solution appears grossly inefficient because it invokes cpio for every file. On a modern system it is hard to beat for speed.
The script copies the file and then deletes the file.
See both "man find" and "man cpio" for the interaction between "find" and "cpio" when copying files.

# This cd is important. We do not want absolute paths.
cd /data/NewJersey
find . -type f -mtime +33 -print|while read filename
do
        # Copy files preserving permissions and create any directory needed 
        echo "${filename}"|cpio -pdumv /home/scripts/NJ; ERROR=$?
        if [ $ERROR = 0 ]
        then
                  # Uncomment next line when tested thoroughly
                   echo rm "${filename}"
        else
                   echo "Copy failed for: ${filename}"
        fi
done