cp is a very useful utility under Unix, and extremely powerful. It enables one person to copy more information in a second than a fourteenth century monk could do in a year.
Be careful with cp if you don't have a lot of disk
space. No one wants to see Error saving--disk full
. cp can
also overwrite existing files--I'll talk more about that danger later.
The first parameter to cp is the file to copy--the last is where to copy it. You can copy to either a different filename, or a different directory. Let's try some examples:
The first cp command I ran took the file /etc/rc;, which contains commands that the Unix system runs on boot-up, and copied it to my home directory. cp doesn't delete the source file, so I didn't do anything that could harm the system. So two copies of /etc/rc exist on my system now, both named rc, but one is in the directory /etc and one is in /home/larry.
Then I created a third copy of /etc/rc; when I typed cp rc frog--the three copies are now: /etc/rc, /home/larry/rc and /home/larry/frog. The contents of these three files are the same, even if the names aren't.
The above example illustrates two uses of the command cp. Are there any others? Let's take a look:
How did I just use cp? Evidentally, cp can take more
than two parameters. What the above command did is copied all the files
listed (frog and rc) and placed them in the rc_version
directory. In fact, cp can take any number of parameters, and
interprets the first n-1 parameters to be files to copy, and the parameter as what directory to copy them too.
You cannot rename files when you copy more than one at a time--they always keep their short name. This leads to an interesting question. What if I type cp frog rc toad, where frog and rc exist and toad isn't a directory? Try it and see.
One last thing in this section--how can you show the parameters that cp takes? After all, the parameters can mean two different things. When that happens, we'll have two different lines:
cp source destination-name
cp file1 file2 ...fileN destination-directory