*nix Documentation Project
·  Home
 +   man pages
·  Linux HOWTOs
·  FreeBSD Tips
·  *niX Forums

  man pages->HP-UX 11i man pages -> cp (1)              


 cp(1)                                                                 cp(1)

 NAME    [Toc]    [Back]
      cp - copy files and directory subtrees

 SYNOPSIS    [Toc]    [Back]
      cp [-f|-i] [-p] [-S] [-e extarg ] file1 new_file

      cp [-f|-i] [-p] [-S] [-e extarg ] file1 [file2 ...] dest_directory

      cp [-f|-i] [-p] [-S] [-R|-r] [-e extarg ] directory1 [directory2 ...]

 DESCRIPTION    [Toc]    [Back]
      cp copies:

           +  file1 to new or existing new_file,
           +  file1 to existing dest_directory,
           +  file1, file2, ...  to existing dest_directory,
           +  directory subtree directory1, to new or existing
              dest_directory.  or
           +  multiple directory subtrees directory1, directory2, ...  to
              new or existing dest_directory.

      cp fails if file1 and new_file are the same (be cautious when using
      shell metacharacters).  When destination is a directory, one or more
      files are copied into that directory.  If two or more files are
      copied, the destination must be a directory.  When copying a single
      file to a new file, if new_file exists, its contents are destroyed.

      If the access permissions of the destination dest_directory or
      existing destination file new_file forbid writing, cp aborts and
      produces an error message ``cannot create file''.

      To copy one or more directory subtrees to another directory, the -r
      option is required.  The -r option is ignored if used when copying a
      file to another file or files to a directory.

      If new_file is a link to an existing file with other links, cp
      overwrites the existing file and retains all links.  If copying a file
      to an existing file, cp does not change existing file access
      permission bits, owner, or group.

      When copying files to a directory or to a new file that does not
      already exist, cp creates a new file with the same file permission
      bits as file1, modified by the file creation mask of the user if the
      -p option was not specified, and then bitwise inclusively ORed with
      S_IRWXU.  The owner and group of the new file or files are those of
      the user.  The last modification time of new_file (and last access
      time, if new_file did not exist) and the last access time of the
      source file1 are set to the time the copy was made.

 Hewlett-Packard Company            - 1 -      HP-UX 11i Version 2: Sep 2004

 cp(1)                                                                 cp(1)

    Options    [Toc]    [Back]
      -i      (interactive copy) Cause cp to write a prompt to standard
              error and wait for a response before copying a file that would
              overwrite an existing file.  If the response from the standard
              input is affirmative, the file is copied if permissions allow
              the copy.  If the -i (interactive) and -f (forced-copy)
              options are both specified, the -i option is ignored.

      -f      Force existing destination pathnames to be removed before
              copying, without prompting for confirmation.  This option has
              the effect of destroying and replacing any existing file whose
              name and directory location conflicts with the name and
              location of the new file created by the copy operation.

      -p      (preserve permissions) Causes cp to preserve in the copy as
              many of the modification time, access time, file mode, user
              ID, and group ID as allowed by permissions.

      -r      (recursive subtree copy) Cause cp to copy the subtree rooted
              at each source directory to dest_directory.  If dest_directory
              exists, it must be a directory, in which case cp creates a
              directory within dest_directory with the same name as file1
              and copies the subtree rooted at file1 to
              dest_directory/file1.  An error occurs if dest_directory/file1
              already exists.  If dest_directory does not exist, cp creates
              it and copies the subtree rooted at file1 to dest_directory.
              Note that cp -r cannot merge subtrees.

              Usually normal files and directories are copied.  Character
              special devices, block special devices, network special files,
              named pipes, symbolic links, and sockets are copied, if the
              user has access to the file; otherwise, a warning is printed
              stating that the file cannot be created, and the file is

              dest_directory should not reside within directory1, nor should
              directory1 have a cyclic directory structure, since in both
              cases cp attempts to copy an infinite amount of data.

              Under UNIX95 flag set, cp will exit with error if multiple
              sources are being copied to a non-existing directory.

      -R      (recursive subtree copy) The -R option is identical to the -r

              With the -R and -r options, in addition to regular files and
              directories, cp also copies FIFOs, character and block device
              files and symbolic links.  Only superusers can copy device
              files.  All other users get an error.  Symbolic links are
              copied so the target points to the same location that the
              source did.

 Hewlett-Packard Company            - 2 -      HP-UX 11i Version 2: Sep 2004

 cp(1)                                                                 cp(1)

              Warning:  While copying a directory tree that has device
              special files, use the -r option; otherwise, an infinite
              amount of data is read from the device special file and is
              duplicated as a special file in the destination directory
              occupying large file system space.

      -e extarg
              Specifies the handling of any extent attributes of the file[s]
              to be copied.  extarg takes one of the following values.

                   warn      Issues a warning message if extent attributes
                             cannot be copied, but copies the file anyway.
                   ignore    Does not copy the extent attributes.
                   force     Fails to copy the file if the extent attribute
                             can not be copied.

              Extent attributes can not be copied if the files are being
              copied to a file system which does not support extent
              attributes or if that file system has a different block size
              than the original.  If -e is not specified, the default value
              for extarg is warn.

      -S      Specifies "safe" mode.  This minimizes the impact of cp on the
              performance of the system by opening the target file using the
              O_DSYNC flag.  This is recommended when the total size of the
              copy (not of a single file) is a significant portion of the
              size of system buffer cache.  Usage of this option increases
              copy time.

    Access Control Lists (ACLs)    [Toc]    [Back]
      If new_file is a new file, or if a new file is created in
      dest_directory, it inherits the access control list of the original
      file1, file2, etc., altered to reflect any difference in ownership
      between the two files (see acl(5) and aclv(5)).  In JFS file systems,
      new files created by cp do not inherit their parent directory's
      default ACL entries (if any), but instead retain the ACLs of the files
      being copied.  When copying files from a JFS file system to an HFS
      file system or vice versa, optional ACL entries are lost.

    Environment Variables
      UNIX95 specifies using the XPG4 behaviour for this command.

      LC_CTYPE determines the interpretation of text as single and/or
      multi-byte characters.

      LANG and LC_CTYPE determine the local language equivalent of y (for
      yes/no queries).

      LANG determines the language in which messages are displayed.

 Hewlett-Packard Company            - 3 -      HP-UX 11i Version 2: Sep 2004

 cp(1)                                                                 cp(1)

      If LC_CTYPE is not specified in the environment or is set to the empty
      string, the value of LANG is used as a default for each unspecified or
      empty variable.  If LANG is not specified or is set to the empty
      string, a default of "C" (see lang(5)) is used instead of LANG.  If
      any internationalization variable contains an invalid setting, cp
      behaves as if all internationalization variables are set to "C".  See

    International Code Set Support    [Toc]    [Back]
      Single- and multi-byte character code sets are supported.

 EXAMPLES    [Toc]    [Back]
      The following command moves the directory sourcedir and its contents
      to a new location (targetdir) in the file system.  Since cp creates
      the new directory, the destination directory targetdir should not
      already exist.

           cp -r sourcedir targetdir && rm -rf sourcedir

      The -r option copies the subtree (files and subdirectories) in
      directory sourcedir to directory targetdir.  The double ampersand (&&)
      causes a conditional action.  If the operation on the left side of the
      && is successful, the right side is executed (and removes the old
      directory).  If the operation on the left of the && is not successful,
      the old directory is not removed.

      This example is equivalent to:

           mv sourcedir targetdir

      To copy all files and directory subtrees in the current directory to
      an existing targetdir, use:

           cp -r * targetdir

      To copy all files and directory subtrees in sourcedir to targetdir,

           cp -r sourcedir/* targetdir

      Note that directory pathnames can precede both sourcedir and

      To create a zero-length file, use any of the following:

           cat /dev/null >file
           cp /dev/null file
           touch file

 DEPENDENCIES    [Toc]    [Back]

 Hewlett-Packard Company            - 4 -      HP-UX 11i Version 2: Sep 2004

 cp(1)                                                                 cp(1)

    NFS    [Toc]    [Back]
      Access control lists of networked files are summarized (as returned in
      st_mode by stat()), but not copied to the new file.  When using mv or
      ln on such files, a + is not printed after the mode value when asking
      for permission to overwrite a file.

 AUTHOR    [Toc]    [Back]
      cp was developed by AT&T, the University of California, Berkeley, and

 SEE ALSO    [Toc]    [Back]
      cpio(1), ln(1), mv(1), rm(1), link(1M), lstat(2), readlink(2),
      stat(2), symlink(2), symlink(4), acl(5), aclv(5).

      cp: SVID2, SVID3, XPG2, XPG3, XPG4, POSIX.2

 Hewlett-Packard Company            - 5 -      HP-UX 11i Version 2: Sep 2004
[ Back ]
 Similar pages
Name OS Title
pax HP-UX Extracts, writes, and lists archive files; copies files and directory hierarchies
rcpDevice IRIX copy a file or directory to or from a remote host
cpio HP-UX copy file archives in and out; duplicate directory trees
pax OpenBSD read and write file archives and copy directory hierarchies
pax FreeBSD read and write file archives and copy directory hierarchies
doscp HP-UX copy to or from DOS files
cp FreeBSD copy files
cp OpenBSD copy files
lifcp HP-UX copy to or from LIF files
cpio FreeBSD copy files to and from archives
Copyright © 2004-2005 DeniX Solutions SRL
newsletter delivery service