Breadcrumbs 
Learning >> Documentation >> File System >> Copying files
 
Recent News
We Want You!
Come and get involved! (And Christmas Party!
[ more ]
Make your own Xbox games!
Learn to make Xbox 360 games
[ more ]
New Committee
A new committee has been appointed.
[ more ]
Copying Files
Copying Files

cp [source] [destination]

First lets create a file to mess around with.

$ touch coverletter
$ ls
coverletter

The touch command updates the modified time of a file, but can also create a file if one does not exist.
Now lets copy this file.

$ cp coverletter coverletter_old
$ ls
coverletter coverletter_old

The file has been copied!
But be very careful, if the detination file already exists, it will be overwritten and you will lose all data that file contained. You can can protect yourself from this as follows:

$ cp -i coverletter coverletter_old
cp: overwrite 'coverletter_old'? n

The "-i" option will make the cp command check to see if a file already exists and ask you to confirm you want to overwrite it. Enter 'y' for yes or 'n' for no.

You can copy a file to a directory as follows:

$ cp coverletter letters/

You can also copy multiple files to a directory in the same way:

$ cp coverletter coverletter1 coverletter2 letters/

Or you can be fancy and use a wildcard:

roryd@frink:~$ cp coverletter* letters/

The wildcard "*" matches any character, including a blank. So "coverletter*" will match "coverletter", "coverletter1", "coverletter2" etc. and move them all into one directory.

Finally, you can also rename files when copying.

$ cp coverletter letters/current_coverletter

This copys the file coverletter into the letters directory with a new name.

Lets find out how to just move files.