I'd like to copy the modification and access times, but not the user ID. If I use
cp -p source targetIt will copy everything.
I'm trying to copy files to a different user but keep the original dates intact.
2 Answers
From the cp manual of GNU coreutils:
-psame as--preserve=mode,ownership,timestamps
So, you are looking for
cp --preserve=mode,timestamps source targetBut if you use some non-GNU operating system, you might not be able to use these long option with cp. In that case, you can give rsync a try, where you can specify in details which attributes should be preserved (search the man page for "preserve"):
-H, --hard-links preserve hard links -p, --perms preserve permissions -E, --executability preserve executability -A, --acls preserve ACLs (implies -p) -X, --xattrs preserve extended attributes -o, --owner preserve owner (super-user only) -g, --group preserve group --devices preserve device files (super-user only) --specials preserve special files -t, --times preserve modification timesSo, to resemble the cp command above, use something like
rsync -pEt source targetTo test the command beforehand, you can initiate a "dry-run" with -n. Add also the verbose parameter -v to see what's going on:
rsync -nv -pEt source targetHowever, I'm not sure, if the access time will be copied, too.
5I believe the ditto command preserves dates.
1ditto src target