Sunday, October 08, 2006

Copying a File/Directory

Copy a file or directory is very easy. Well, it's always easy once you know... You will need to use the the cp (copy) utility. It's a very easy utility to use.

Here are some quick points.

cp originalfile newfile -- Copies contents of originalfile into newfile. The permissions and attribute information are not preserved.

cp -p originalfile newfile -- same as above, except the permission and attribute information are preserved.

cp -pr originaldirectory newdirectory -- same as above, except the permissions/attribute information are preserved. One big thing here, the -r is recursive. It copies the directory and its contents.

e.g.
#cp esofthub.dat esofthub1.dat (permissions not preserved and user/group information possibly different)
#cp -p esofthub.dat esofthub1.dat (permissions and attribute information preserved)
#cp -pr esofthub_dir esofthub1_dir (permissions and attribute information preserved)

No comments: