->Title Page
->Intro
->Unix
-->Overview
-->File Structure
-->Online Manual
-->Basic Commands
--->Logging In
--->Password
--->Getting Out
--->Listing files
--->Catenate
--->Paging
->Copying
--->Removing
--->Renaming
--->Directory trees
--->Make/Remove Directories
-->Additional Commands
-->Login files
-->Special characters
-->Miscellaneous Tips
-->Things to try
->Vi editor
->Mirror sites
->Further reading

[ Up ]
[Prev][Home][Next]
[Author]

Unix ---> Copying

The cp (copy) command lets you duplicate a file of choice. Here is an explanation by examples:


    cp cocoon butterfly
makes a duplicate of the file cocoon and gives it the name butterfly. Note that the filenames can include pathnames as well.


    cp /home/cernan/taylor/tex/contract ../contract.bak
makes a copy of the file contract found in the /home/cernan/taylor/tex directory and places it one directory level above the working directory in a file called contract.bak.

If /home/cernan/taylor/tex is a directory, then


    cp report /home/cernan/taylor/tex
will place a copy of report in the /home/cernan/taylor/tex directory with the name report.


    cp /home/cernan/taylor/tex/headlines .
will copy the file headlines in the /home/cernan/taylor/tex directory into the working directory. The name will remain unchanged.


    cp /home/cernan/taylor/tex/* .
will copy all the files (but not the subdirectories) in /home/cernan/taylor/tex into the working directory. You can copy all the subdirectories in the directory and files contained in them by using the -r (recursive) flag as follows:


    cp -r /home/cernan/taylor/tex/* .
Another useful flag is the -i (interactive) flag which prompts you if you are about to overwrite an existing file.

Please notify owners of webpages with outdated links to these pages

Find this site useful? Want to give something back?

© 1993-2001 Christopher C. Taylor