techxplore blog
22Jun

Linux Sudo Copy File Preserve Permission Date Stamp

A simple day to day task in using a computer such as copying a file could be daunting in a new environment. Well a friend new to Linux operating system is blown away with such a task. A person who is accustomed to GUI (Graphic User Interface) environment like MS Windows operating system freaks out.

Anyway, copying a file in Linux is usually done via “cp” command. Some systems does not allow use of “cp” command. It should be done via “sudo” (allow a super user to do on ones behalf).
Example:
$sudo cp sourcefilename targetfilename

The above command requires that the user is in the list of “sudo” users. The problem with using such command is it changes the ownership to “root” and date stamp to system date. There are cases when we don’t want such scenario.

Thus, to preserve the ownership, permission, and date stamp the “cp” command is used with some parameters.
Example:
$sudo cp sourcefilename targetfilename -p

The added parameter “-p” tells “cp” command to preserve the ownership, permission, and date stamp.

Leave a Reply