CP(1) CP(1)
cp, ln, mv - copy, link or move files
cp [ -aDfirRp -b size -tP -e size ] file1 [file2 ...] target
ln [ -sif ] file1 [file2 ...] target
mv [ -if ] file1 [file2 ...] target
file1 is copied (linked, moved) to target. Under no circumstance can
file1 and target 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 an existing file, its contents
are destroyed, except in the ln and ln -s case where the command will
fail and ln will write a diagnostic message to standard error (use the -i
or -f option to override this behavior). NOTE that this is a change from
the historical ln execution.
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. 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. Additionally, if target exists, then the -f option will
force the link when ln -s is specified. If cp determines that the mode
of target forbids writing, the command will fail and cp will write a
diagnostic message to standard error (use the -i or -f option to override
this behavior).
If the -f option is specified with mv, any previous occurrences of the -i
option will be ignored.
For mv, if file1 is a directory, mv will perform actions equivalent to
the rename function. If this fails for any reasons other than those
described for the errno [EXDEV], mv will write a diagnostic message to
standard error, do nothing more with the current source file, and go on
to any remaining source files. Otherwise, the file hierarchy rooted in
file1 will be duplicated as a file hierarchy rooted in the destination
path. The time of last data modification, the time of last access, the
user ID and group ID and file mode will be duplicated. If the user ID,
group ID or file mode of a regular file cannot be duplicated, the file
mode bits S_ISUID and S_ISGID will not be duplicated. When files are
duplicated to another file system, the invoking process must has read
access to each file being duplicated. If the duplication of the file
hierarchy fails for any reason, mv will write a diagnostic message to
standard error, do nothing more with the current source_file, and go on
to any remaining source_files. If the duplication of the file
characteristics fails for any reason, mv will write a diagnostic message
to standard error, but this failure will not cause mv to modify its exit
status. If the copying or removal of file1 is prematurely terminated by
a signal or error, mv may leave a partial copy of file1 at the source or
destination. The mv utility will not modify both file1 and the
Page 1
CP(1) CP(1)
destination path simultaneously; termination at any point will leave
either file1 or the destination path complete.
For mv, 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 cp is invoked, if target is not an existing file, a new file is
created which 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.
When copying between XFS filesystems, cp will replicate holes in file1 in
target.
If the -p option is specified, cp will duplicate the following
characteristics of each source file in the corresponding destination
file:
1. The time of last data modification and time of last access. If this
duplication fails for any reason, cp will write a diagnostic message
to standard error.
2. The user ID and group ID. If this duplication fails for any reason,
cp will write a diagnostic message to standard error.
3. The file permission bits and the S_ISUID and S_ISGID bits. Other,
implementation-dependent, bits may be duplicated as well. If this
duplication fails for any reason, cp will write a diagnostic message
to standard error.
If the user ID or the group ID cannot be duplicated,
the file permission bits S_ISUID and S_ISGID will be cleared. If
these bits are present in the source file but are not duplicated in
the destination file, cp will write a diagnostic message to standard
error.
The -a option to cp will copy user mode XFS attributes, the option is
silently ignored if any of the files involved is not on an XFS
filesystem.
The -D option to cp specifies that direct IO should be used to copy the
file, file data is not buffered in the kernel. The -b blocksize option
can be used to specify a specific blocksize to use, this option can also
be used without -D . Direct IO will only function on XFS and EFS
filesystems.
Page 2
CP(1) CP(1)
If the -t option is specified then cp will attempt to create an output
file on the realtime extent of the target filesystem. The -e extsize
option can be used to specify an extent size other than the default for
the filesystem. The -P option is used to indicate that the file size
should be padded out to a legitimate size for a realtime file if file1 is
not a legitimate size. The target filesystem must be XFS for the -t
option to work.
With the -s option ln creates symbolic links. A symbolic link is a
special kind of file whose contents are the name of another file (see
symlink(2)). A symbolic link contains the name of the file to which it
is linked. Most system calls, including open(2), stat(2), and access(2),
substitute these contents when the name of a symbolic link occurs in a
pathname. This process is known as ``following'' symbolic links.
stat(2), readlink(2), symlink(2), and unlink(2) also do this
substitution, except on the last component of the pathname. Thus, they
are said not to ``follow'' symbolic links. Symbolic links may span file
systems and may refer to directories. Note that cp ``follows'' symbolic
links (except when using the -R option, while mv and ln do not ``follow''
symbolic links.
If the -i option is specified with cp, ln, or mv and target exists, the
user is prompted with the message:
overwrite target?
If the user answers with a line starting with `y', the move or copy
continues. Any other reply prevents the command from completing. When
creating soft links this warning often indicates that the user has
swapped the file and target parameters, which results in replacement of
the target file with a dangling symbolic link.
If the -i option is specified with mv, any previous occurrences of the -f
option will be ignored.
If the -r or -R option is specified with cp and any of the source files
are directories, cp copies each subtree rooted at that name; in this case
target must be a directory. The difference between -r and -R is that -r
causes cp to follow symbolic links and -R does not. (Note that the
behavior of -R is defined by POSIX, whereas the behavior of -r is
particular to this implementation.)
If the -R option is specified with cp and the source file is not of type
directory or regular file, then the following steps will be taken:
1. The target file will be created with the same file type as file1.
2. If file1 is a type FIFO, the target file permission bits will be the
same as those of file1 modified by the file creation mask of the
user if the -p option was not specified.
If this creation fails for any reason, cp will write a diagnostic
Page 3
CP(1) CP(1)
message to standard error, do nothing more with the source file and
go on to any remaining files.
chmod(1), cpio(1), rm(1).
ln without -s will not link across file systems. This restriction is
necessary because file systems can be added and removed.
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.
PPPPaaaaggggeeee 4444 [ Back ]
|