Generally when you copy a file, the file attributes may get changed during the copy. You can use cp –preserve[=ATTR_LIST] to preserve the specified attributes (default: mode,ownership,timestamps), if possible additional attributes: context, links, xattr, all.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
echo "hello" > myfile ## Create some files and directories mkdir mydir ls -l myfile ## returns -rw-r--r-- 1 user user 6 May 14 19:45 myfile cp myfile mydir ls -l mydir/myfile ## returns -rw-r--r-- 1 user 197121 6 May 14 19:48 myfile ## observe the timestamp has changed, timestamp is one of the file attributes ## for simplicility we will only preserve the timestamp ## but other supported attributes can also be preserved. cp --preserve=timestamps myfile mydir/myfile ls -l mydir/myfile ## returns -rw-r--r-- 1 user 197121 6 May 14 19:45 mydir/myfile ## timestamp remains the same. rm -r my* |