You can use cp -p (same as –preserve=mode, ownership, timestamps) to preserve the source attributes like permissions, etc.
1 2 3 4 5 6 7 8 9 10 11 12 |
echo "hello" > myfile ## Create some files and directories mkdir mydir ls -l myfile ## returns -rw-r--r-- 1 user user 6 May 14 19:52 myfile cp myfile mydir ls -l mydir/myfile ## returns -rw-r--r-- 1 user 197121 6 May 14 19:54 mydir/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 -p myfile mydir/myfile ls -l mydir/myfile ## returns -rw-r--r-- 1 user 197121 6 May 14 19:52 mydir/myfile ## timestamp remains the same. |