Section 3.19. Copying a File: cp


[Page 60 (continued)]

3.19. Copying a File: cp

After moving into the "lyrics" directory, I decided to work on a second version of my lyrics. I wanted to keep the first version for posterity, so I copied "heart.ver1" into a new file called "heart.ver2" and then edited the new file. To copy the file I used the cp utility, which works as described in Figure 3-23.


[Page 61]

Figure 3-23. Description of the cp command.

Utility: cp -i oldFileName newFileName

cp -ir { fileName }* directoryName

The first form of cp copies oldFileName to newFileName. If the label newFileName already exists, it is replaced. The -i option prompts you for confirmation if newFileName already exists. The second form of cp copies a list of files into directoryName. The -r option causes any source files that are directories to be recursively copied, thus copying the entire directory structure.


cp actually does two things:

  • It makes a physical copy of the original file's contents.

  • It creates a new label in the directory hierarchy that points to the copied file.

The new copy of the original file can therefore be edited, removed, and otherwise manipulated without having any effect on the original file. Here's how I copied the "heart.ver1" file:

$ cp heart.ver1 heart.ver2             ...copy to "heart.ver2". $ ls -lG heart.ver1 heart.ver2         ...confirm. -rw-r--r--  1     glass   106     Jan 30  23:28 heart.ver1 -rw-r--r--  1     glass   106     Jan 31  00:12 heart.ver2 $ _ 





Linux for Programmers and Users
Linux for Programmers and Users
ISBN: 0131857487
EAN: 2147483647
Year: 2007
Pages: 339

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net