I was using the following copy command to take backup of my datastore

cp -pr $src $dest

Which gives me the following warning while using with NFS and returns an error code but the files are actually getting copied.

cp: preserving times for ‘$src/file1’: Invalid argument

Is there any alternative method to do this? I want to get rid of the warnings and wrong return code. I do not care about preserving time stamps, but other attributes such as mode and ownership should be preserved.

  • You could use tar instead and have it preserve the permissions etc. of the source files in the archive. – Kusalananda Jan 10 '17 at 10:10

The man page for cp shows that there are options available to control which attributes are included.

-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

It follows, therefore, that you could follow -p with something like --no-preserve=timestamps.

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.