Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ cp(1) — Interactive 3.2r4.1

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

chmod(1)

cpio(1)

ls(1)

rm(1)

chdir(2)

link(2)

open(2)

readlink(2)

stat(2)

symlink(2)

cp(1)  —  

NAME

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

SYNOPSIS

cp [ −p ] [ 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 will cp or mv allow file1 and target to be the same (take care when using sh(1) metacharacters). If target is a directory, then one or more files are copied (linked, moved) to that directory.  (If target is a file, its contents are ­destroyed.) 

If mv or ln determines that the mode of target forbids writing, it will print the mode (see chmod(2)), ask for a response, and read the standard input for one line. If the line begins with y, the mv or ln occurs, if permissible; if not, the command exits.  For mv, when source parent directories or the target directory is writable and has the sticky bit set, any of the following conditions must be true:

the user must own the file
the user must own the directory
the file must be writable to the user
the user must be the superuser

When the −f option is used, or if the standard input is not a terminal, no questions are asked and the mv or ln is done. 

Only mv will allow file1 to be a directory, in which case the directory rename will occur only if the two directories have the same parent; file1 is renamed target. 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. 

When using cp, if target is not a file, a new file is created which has the same mode as file1 except that the sticky bit is not set unless you are the superuser; 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.  If the −p (preserve) option is used, the modification time and permission modes will be preserved.  Without the −p option, 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. 

The −s option to ln is used to create a symbolic link, which is a special directory entry that points to another named file.  The linked-to file is actually used whenever an open(2) or chdir(2) is performed on the link. Symbolic links can span file systems and point to directories. In fact, you can create a symbolic link that points to a file that is currently absent from the file system; removing the file that it points to does not affect or alter the symbolic link itself.
A symbolic link to a directory behaves differently than might be expected in certain cases.  While an ls(1) on such a link displays the files in the pointed-to directory, an ls −l displays information about the link itself:

$ ln −s dir link
$ ls link
file1
file2
file3
$ ls −l link
lrwxrwxr-x   1 user     group          3 Jan  5 13:37 link -> dir

When you cd(1) to a directory through a symbolic link, you are taken to the pointed-to location within the file system.  This means that the parent of the new working directory is not the parent of the symbolic link, but rather the parent of the pointed-to directory.  For instance, in the following case the final working directory is /usr and not /home/user/linktest:

$ pwd
/home/user/linktest
$ ln −s /usr/tmp symlink
$ cd symlink
$ cd ..
$ pwd
/usr

SEE ALSO

chmod(1), cpio(1), ls(1), rm(1), chdir(2), link(2), open(2), readlink(2), stat(2), symlink(2). 

WARNINGS

ln cannot create hard links across file systems.  If you need to link across file systems, use the −s option to ln to create a symbolic link. 

BUGS

If file1 and target lie on different file systems, mv must copy the file and delete the original.  In this case any linking relationship with other files is lost. 

ADDED VALUE

This entry, supplied by SunSoft, Inc., contains enhancements to UNIX ­System V. 

\*U  —  Version 1.0

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