Copy a file and keep the same timestamp of the original file
772
I need to a copy file and after that I need to change the timestamp attributes as the original file. How can I do it with the terminal or any other way?
You can preserve the timestamp of the original file when copying using cp by adding the -p or --preserve option:
-p same as --preserve=mode,ownership,timestamps
--preserve[=ATTR_LIST]
preserve the specified attributes (default: mode,ownership,time‐
stamps), if possible additional attributes: context, links,
xattr, all
So to preserve only the timestamp
cp --preserve=timestamps oldfile newfile
or to preserve mode and ownership as well
cp --preserve oldfile newfile
or
cp -p oldfile newfile
Additional options are available for recursive copying - a common one is cp -a (cp --archive) which additionally preserves symbolic links.
You can preserve the timestamp of the original file when copying using
cp
by adding the-p
or--preserve
option:So to preserve only the timestamp
or to preserve mode and ownership as well
or
Additional options are available for recursive copying - a common one is
cp -a
(cp --archive
) which additionally preserves symbolic links.If you want to preserve the original timestamps, use
This copies the timestamps from another file.
See this blog post for more: Fake File Access, Modify and Change TimeStamps