Sohan's Blog

Living the Developer's Life

Preserve Ownership, Mode and Other Attributes While Copying in Linux

I dare not say, I am savvy at Linux :-)

Recently, I ran into a problem where I found that upon executing a copy command, my source and destination files had different permissions and attributes (i-nodes), but I badly needed the permissions to be preserved in the destination files/folders. The following command will preserve the attributes -

cp -p source destination

here, the switch p (-p) does the trick, it preserves the permissions, modes and other attributes to resemble the source.

Hope this helps some of you with similar needs!