4

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.

8

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

| improve this answer | |
  • It will leave the original directory as-is which needs to be deleted too – Moon Feb 5 '18 at 4:34
  • Yes, this is what cp does, you need do a deletion after copy. – αғsнιη Feb 5 '18 at 4:48
  • Yes. I am more like looking for a single line mv alternative if available. – Moon Feb 5 '18 at 4:55
  • 1
    there is no AFAIK, only option is using rsync with --remove-source-files option to delete files only but this will not delete directory itself, so you need do directory deletion too after that. – αғsнιη Feb 5 '18 at 5:02
  • 1
    So cp -r --preserve=all is the best I can get? – 0xc0de Jan 24 at 11:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.