Wednesday, February 13, 2008

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!