I would like to move a directory from one location to another but when I do I can see that the timestamp gets changed. Is there any way to retain the timestamp as original?
Have looked at the man page of
mv but couldn't find any existing options.
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
cp as following,
mv doesn't do.
cp -r -p /path/to/sourceDirectory /path/to/destination/
from man cp:
-p same as --preserve=mode,ownership,timestamps --preserve[=ATTR_LIST] preserve the specified attributes (default: mode,ownership,timestamps), if possible additional attributes: context, links, xattr, all
then after copy done, delete the sourceDirectory.
On linux, this works:
timestamp=$(stat -c %y foldername) mv foldername new_foldername touch -d "$timestamp" new_foldername
stat -c %y command returns the modification date of the folder, in readable form. That value is retained and used with the command
touch -d "$timestamp" to set the time of the new folder.