Switch to SpeakEasy.net DSL

The Modular Manual Browser

Home Page
Manual: (SunOS-4.1.3)
Apropos / Subsearch:
optional field

CP(1)                       General Commands Manual                      CP(1)

       cp - copy files

       cp [ -ip ] filename1 filename2
       cp -rR [ -ip ] directory1 directory2
       cp [ -iprR ] filename ...  directory

       cp copies the contents of filename1 onto filename2.  The mode and owner
       of filename2 are preserved if it  already  existed;  the  mode  of  the
       source  file  is used otherwise.  If filename1 is a symbolic link, or a
       duplicate hard link, the contents of the file that the link  refers  to
       are copied; links are not preserved.

       In  the  second  form, cp recursively copies directory1, along with its
       contents and subdirectories, to directory2.   If  directory2  does  not
       exist,  cp  creates  it  and duplicates the files and subdirectories of
       directory1 within it.  If directory2 does exist, cp makes a copy of the
       directory1  directory within directory2 (as a subdirectory), along with
       its files and subdirectories.

       In the third form, each filename is copied to the indicated  directory;
       the basename of the copy corresponds to that of the original.  The des-
       tination directory must already exist for the copy to succeed.

       cp refuses to copy a file onto itself.

       -i     Interactive.  Prompt for confirmation whenever  the  copy  would
              overwrite  an  existing  file.   A y in answer confirms that the
              copy should proceed.  Any other answer prevents  cp  from  over-
              writing the file.

       -p     Preserve.   Duplicate not only the contents of the original file
              or directory, but also  the  modification  time  and  permission

       -R     Recursive.  If any of the source files are directories, copy the
              directory along with its files (including any subdirectories and
              their files); the destination must be a directory.

       To copy a file:
              example% cp goodies goodies.old
              example% ls goodies*
              goodies goodies.old

       To  copy  a directory, first to a new, and then to an existing destina-
       tion directory:

              example% ls ~/bkup
              /usr/example/fred/bkup not found
              example% cp -r ~/src ~/bkup
              example% ls -R ~/bkup
              x.c y.c z.sh
              example% cp -r ~/src ~/bkup
              example% ls -R ~/bkup
              src x.c y.c z.sh
              x.c y.c z.sh

       To copy a list of files to a destination directory:
              example% cp ~/src/*   /tmp

       cat(1V), ln(1V), mv(1), pr(1V), rcp(1C), tar(1)

       Beware of a recursive copy like this:

              example% cp -r ~/src ~/src/bkup

       which keeps copying files until it fills the entire file system.

       cp copies the contents of files pointed to by symbolic links.  It  does
       not  copy  the  symbolic link itself.  This can lead to inconsistencies
       when directory hierarchies are replicated.  Filenames that were  linked
       in the original hierarchy are no longer linked in the replica.  This is
       also true for files with multiple hard links.  See ln(1V)  for  details
       about  symbolic links and hard links.  You can preserve links in repli-
       cated hierarchies by using tar(1) to copy them.

                               9 September 1987                          CP(1)