copying unreference files and keeping absolute path

Hi guys,

I'm creating a script that basically remove unreference files so at the moment I have something like:
DAYS=30
for DIRECTORY in `mount | awk '{ print $7}'`
do
find $DIRECTORY -type f -atime +$DAYS < ~/files.log
done

for FILE in `awk '{print $1}' ~/files.log`
do
cp $FILE /tmp/$FILE
done

but I need to create also the directories so I can see from where the files were copied originally (e.g /stage/data/log/remote_copy.txt and after the copy I should end up with /tmp/stage/data/log/remote_copy.txt) but with the cp command I can't do it. If there any other way to get this done. Please any ideas . thanks.

Try and play around with the cpio command:

for DIRECTORY in `mount | awk '{ print $7}'`
do
  find $DIRECTORY -type f -atime +$DAYS | cpio -pvdmu /tmp
done

Check the explanation of the options in the man page of cpio.

Regards

thanks mate. It works fine. thanks.