next up previous contents
Next: rm Up: Unix Commands Previous: cd and pwd   Contents

cp


The cp command stands for ``copy.'' Use this to copy from one location to another location.

The first arguments are the source, while the last argument is the destination. If the destination is a file, the sources will be copied over that file. If the file doesnt exist yet, it is created and the sources copied over to that file. If the destination is a directory, the sources will be copied to that directory, potentially copying over files already there.

Example:

[jdpoisso@legio data]$ ls 
architechture.c  architechture.h  image  interface.c  interface.h  main.c 
[jdpoisso@legio data]$ cp main.c old_main.c 
[jdpoisso@legio data]$ ls 
architechture.c  image        interface.h  old_main.c 
architechture.h  interface.c  main.c 
[jdpoisso@legio data]$ ls image 
DSCF1692-1.jpg 
[jdpoisso@legio data]$ cp old_main.c image 
[jdpoisso@legio data]$ ls image 
DSCF1692-1.jpg  old_main.c 
[jdpoisso@legio data]$

If the source is a directory you need to use the ``-r'' argument. The source directory (and all the files and directories it contains) will be copied to the destination. The ``image'' in the example below is a directory.

Example:

[jdpoisso@legio data]$ ls 
architechture.c  image        interface.h  old_main.c 
architechture.h  interface.c  main.c 
[jdpoisso@legio data]$ cp -r image new_image 
[jdpoisso@legio data]$ ls 
architechture.c  image        interface.h  new_image 
architechture.h  interface.c  main.c       old_main.c 
[jdpoisso@legio data]$ ls new_image 
DSCF1692-1.jpg  old_main.c 
[jdpoisso@legio data]$



2010-08-27