I am using CentOS 5.5 and would like to move a large amount of folders within one volume, retaining their mtime.
The best solution I could find is like this:
cp -p -r source/data target/
rm -rf source/data
With over 1TB of data on a NFS share, the copying takes forever. I do not want to copy. I want instantaneous move.
When I move a folder using mv source/data target/, the mtime of the folder (not the files) gets set to current time. This is because the contents of folder I am moving get modified by this operation (the .. entry is pointing to a different inode).
I came up with a following shell script I called mv_preserve_mtime.sh:
#!/bin/bash
# Moves source folder to target folder.
# You are responsible for making sure the target does not exist, otherwise this blows up
export timestamp=`stat -c %y $1`
mv "$1" "$2"
touch --date="${timestamp}" $2
Well, that did not work either. The folder's mtime is restored, but all folders within the folder I move (only the ones 1 level deep) get their mtime reset for reasons I do not understand.
Does anyone have a proper, efficient and correct solution?