Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ cp(1) — HP-UX 6.00

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 (take care when using shell metacharacters).  If target is a directory, one or more files are copied (linked, moved) to that directory.  If two or more files (not counting target) are specified for any of these commands, target must be a directory.  If target is a file, its contents are destroyed. 

If the −r option is specified, cp copies for each source directory the subtree rooted at that 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, and file1 should not have a cyclic directory structure, since in these cases cp will attempt to copy an infinite amount of data. 

If the mode of target forbids writing, both mv and ln will 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 exits.  When the −f option is used or if the standard input is not a terminal, mv and ln are performed if possible without prompting for permission. 

The −s option causes 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 will return the linked-to file; an lstat(2) must be done 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.

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 links, the other links remain and target becomes a new file.  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.  If target is a link to a file, all links remain and the file is changed. 

You cannot use mv 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 that is identical to the name of a file contained in the same parent directory. 

EXAMPLES

The following command moves the directory sourcedir and its contents to a new location (targetdir) in the file system. Cp will create the new directory for you.  Therefore, the target directory should not be one that already exists. 

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 (it 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 will copy the file and delete the original.  In this case the mover becomes the owner and any linking relationship with other files is lost.  Ln will not create hard links across file systems. 

DEPENDENCIES

Series 500, 800
Symbolic links are not supported.

Mv will fail if file1 is a directory and target exists or does not have the same parent as file1.

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  —  Version B.1,  May 11, 2021

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