Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ cp(1) — HP-UX 6.20

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

cpio(1)

rm(1)

link(1M)

chmod(2)

lstat(2)

readlink(2)

symlink(2)

symlink(4)

CP(1)  —  HP-UX

NAME

cp, ln, mv − copy, link or move files

SYNOPSIS

cp [ −r ] file1 [ file2 ...  ] target
ln [ −f ] [ −s ] file1 [ file2 ...  ] target
mv [ −f ] file1 [ file2 ...  ] target

DESCRIPTION

File1 is copied (linked, moved) to target. Under no circumstance can file1 and target be the same (be cautious when using shell metacharacters).  If target is a directory, one or more files are copied (linked, moved) into that directory.  If two or more files (excluding target) are specified for any of these commands, target must be a directory.  If target is a file, its contents are destroyed. 

If the mode of target forbids writing, both mv and ln ask permission to overwrite the file.  This is done by printing the mode (see chmod(2)) followed by the first letters of the words yes and no in the current native language, prompting for a response, and reading one line from the standard input.  If the response is affirmative and is permissible, the operation occurs; if not, the command proceeds to the next source file, if any. 

Ln does not permit hard links to a directory. 

Cp permits file1 to be a directory only if the −r option is specified. 

If file1 is a file and target is a link to another file with other links, the other links remain and target becomes a new file when using ln and mv, while cp simply overwrites target, retaining all links. If target is not a file, cp creates a new file that has the same mode as file1, except that the sticky bit is not set unless you are super-user; the owner and group of target are those of the user.  If target is a file, copying a file into target does not change its mode, owner, or group.  The last modification time of target (and last access time, if target did not exist) and the last access time of file1 are set to the time the copy was made. 

Options

−f Perform ln and mv commands without prompting for permission.  This option is assumed when the standard input is not a terminal. 

−r Cause cp to copy the subtree rooted at each source directory to target. If target exists, it must be a directory, in which case cp creates a directory within target with the same name as file1 and copies the subtree rooted at file1 to target/file1. An error occurs if target/file1 already exists.  If target does not exist, cp creates it and copies the subtree rooted at file1 to target. Note that cp −r will not merge subtrees.  Target should not reside within file1, nor should file1 have a cyclic directory structure, since in both cases cp attempts to copy an infinite amount of data. 

−s Cause ln to create symbolic links instead of the usual hard links. A symbolic link contains the name of the file to which it is linked. The referenced file is used when an open(2) operation is performed on the link. A stat(2) on a symbolic link returns the linked-to file; an lstat(2) must be performed to obtain information about the link. The readlink(2) call can be used to read the contents of the symbolic link. Symbolic links can span file systems and can refer to directories.

EXAMPLES

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 target directory should not already exist. 

cp -r sourcedir targetdir && rm -rf sourcedir

The −r option copies the subtree (files) in the directory sourcedir to the 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. 

WARNINGS

If file1 and target exist on different file systems, mv copies the file and deletes the original.  In this case the mover becomes the owner and any linking relationship with other files is lost.  Ln does not create hard links across file systems. 

The mv command cannot be used to perform the following operations:

rename either the current working directory or its parent directory using the "." or ".." notation;

rename a directory to a new name identical to the name of a file contained in the same parent directory. 

AUTHOR

Cp was developed by AT&T, the University of California, Berkeley and HP. 

SEE ALSO

cpio(1), rm(1), link(1M), chmod(2), lstat(2), readlink(2), symlink(2), symlink(4). 

INTERNATIONAL SUPPORT

8- and 16-bit data, 8-bit file names, messages. 

Hewlett-Packard Company  —  May 11, 2021

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026