OSU Computational Physics - Landau Research Group (nacse) -
Next 5.G: Copying Directories  Up 5: Managing Files and Directories  Prev 5.E: Creating Directories  Contents

Basic

§ 5.F:  Copying Files


The Unix command to "copy" files is cp. The cp comand takes the names of two files as arguments:

> cp filefrom fileto

Here the filefrom is copied into (over) the fileto. Beware, if fileto already exists, the old copy is deleted and the new one takes its place. For this reason it's a good idea to use the "interactive" option -i, which makes Unix ask you for permission before a file is copied over (that's how computers are supposed to behave, with a little respect!).

Note that the names of files can be their full pathnames, or just their names in the local directory. (Actually, the "file names" can also be directory names, but that's getting a little ahead of ourselves.) Let's make sure we are in the development directory, and then copy area.f from the prog subdirectory to the file test.f in our current directory:

> cd ~/development
> cp -i prog/area.f test.f

Now try it again so you can see how Unix tries to watch over you so you do not make too many stupid mistakes:

> cp -i prog/area.f test.f
cp: overwrite test.f (y/n)?

You see that Unix asks if you really want to overwrite the test.f (and "suggests" that you respond with a "y" or "n"). Because we just copied this file, there is no need to copy it again. So go ahead and just say "n":

cp: overwrite test.f (y/n)? n