Copying Things

 

In the last post we talked about moving files using mv. What if instead of moving a file from place to place, you’d like to copy the file. Maybe you want to share it with someone, or maybe you want to make a copy of a file so you can change the second file a bit but still keep around the first. So first we’ll make another file. Let’s do this:

Alpha:~ computerlamp$ echo "Storm Trooper" >Clones

So now we can copy this file to a new file, let’s call it StarWars The command we’re going to use is cp which is short for, of all things, copy.

Alpha:~ computerlamp$ cp Clones StarWars

Now if we do a ls, we’ll see:

Alpha:~ computerlamp$ ls
Clones StarWars

If we cat the file StarWars, we’ll see:

Alpha:~ computerlamp$ cat StarWars
Storm Trooper

We can copy files into different directories. If we have a directory named Sith, we can do:

Alpha:~ computerlamp$ cp Clones Sith/

The / means that Sith is a directory, so the cp command expects to copy that file into a directory. We can also copy the file Clones from the Sith directory back into the current directory by:

Alpha:~ computerlamp$ cp Sith/Clones .

Or you can cd into the Sith directory and copy it like:

Alpha:Sith computerlamp$ cp Clones ..

Leave a Reply

Your email address will not be published. Required fields are marked *