[Next] [Up] [Previous] [Contents]
Next: Removing files (rm) Up: Basic commands Previous: Paging display system

Copying files (cp)

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.


c.c.taylor@ieee.org