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.
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