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?
touchdidn't work. Is it themvstep or thetouchstep that changes the mtime of the subdirectories? What OS is on the NFS server, and (if you know) what filesystem type? – Gilles Dec 10 '10 at 20:22mvstep that causes trouble. The NFS server is actually a NetApp storage, I know virtually nothing about its internals. – Roman Zenka Dec 10 '10 at 22:15touchshould have worked. By the way a more portable way would betouch -r "$1" reference.tmp; mv -- "$1" "$2"; touch -r reference.tmp -- "$2"; rm reference.tmp. – Gilles Dec 10 '10 at 22:29statwas not portable. – Roman Zenka Dec 11 '10 at 17:09