Tuesday, 6th January 2009
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.
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:
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:
You can also copy multiple files to a directory in the same way:
Or you can be fancy and use a wildcard:
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.
This copys the file coverletter into the letters directory with a new name.
Lets find out how to just move files.