CP, COPY(1,C) AIX Commands Reference CP, COPY(1,C)
-------------------------------------------------------------------------------
cp, copy
PURPOSE
Copies files.
SYNTAX
one of
+------+ +--------+ +- infile --- directory -+
| cp |---| +----+ |---|^ | |---|
| copy | +-| -f |-+ |+---------+ |
+------+ ^| -i || +-- infile --- outfile --+
|| -p ||
|| -r ||
|| -- ||
|+----+|
+------+
Note: This command does not have MBCS support.
DESCRIPTION
The cp (copy) command copies a source file or the files in a source directory
to a target file or directory. If your output is to a directory, the files are
copied to that directory with the same file name.
If infile is a symbolic link, the link is followed when the copy is performed.
If the link cannot be followed, an error is indicated. If infile is a hidden
directory, a component in that directory is selected. If no selectable
component is present, an error is indicated.
If outfile is a symbolic link, it is followed when the copy is performed. If
outfile is a hidden directory, a component in that directory is selected. If
the standard input is a work station, the user is asked if that component
should be overwritten before the copy is performed. No questions are asked if
the -f option is given. Components of hidden directories are not created
implicitly by the cp command. If no selectable component is found in the
hidden directory, an error is indicated. Hidden directory components may be
created only by cp using the '@' character syntax.
You can also copy special device files. If the file is a named pipe, the data
in the pipe is copied into a regular file. If the file is a device, the file
is read until the end of file is reached and that data is copied into a regular
file.
Processed November 8, 1990 CP, COPY(1,C) 1
CP, COPY(1,C) AIX Commands Reference CP, COPY(1,C)
Notes:
1. Do not name outfile as one of the input files.
2. If you specify a directory for the outfile, the directory must already
exist.
3. If the infile contains subdirectories and the subdirectories do not exist,
the system creates them.
FLAGS
-f No questions asked if outfile is a hidden directory.
-i Prompts the user with the name of the file whenever the copy will cause an
existing file to be overwritten. An answer of y causes the cp command to
continue. Any other answer prevents it from overwriting the file.
-p Preserves the modification times and modes of the infile for the copy.
-r Copies each subtree rooted at the infile (recursive copy). If the infile
is a directory, the outfile must be a directory.
-- Indicates that the arguments following this flag are to be interpreted as
file names. This null flag allows the specification of file names that
start with a (minus).
EXAMPLES
1. To make another copy of a file in the current directory:
cp prog.c prog.bak
This command copies the file "prog.c" to the file "prog.bak". If the file
"prog.bak" does not already exist, the cp command creates it. If the file
"prog.bak" does exist, the cp command replaces it with a copy of "prog.c".
2. To copy a file to another directory:
cp jones /u/nick/clients
This command copies the file "jones" to the file "/u/nick/clients/jones".
3. To copy a file to a new file and preserve the modification date and time:
cp -p smith smith.jr
This command copies the file "smith" to the file "smith.jr". Instead of
creating the file with the current date and time stamp, the system gives
the file "smith.jr" the same date and time as the file "smith".
4. To copy the files and subdirectories in a directory to another new
directory (target directory does not previously exist):
cp -r /u/nick/clients /u/nick/customers
Processed November 8, 1990 CP, COPY(1,C) 2
CP, COPY(1,C) AIX Commands Reference CP, COPY(1,C)
This command creates the new directory "customers" containing copies of the
files, subdirectories, and files rooted at the directory "clients". If
"/u/nick/customers" already exists, this command creates a directory
"clients" within the directory "customers".
5. To copy a specific set of files to another directory:
cp jones lewis smith /u/nick/clients
This command copies the files "jones, lewis," and "smith" to the directory
"/u/nick/clients".
6. To use pattern-matching characters to copy files:
cp programs/*.c .
This command copies the files that end with ".c" that are located in the
directory "programs" to the current directory (.). You must type a space
between the "c" and the final period.
RELATED INFORMATION
See the following commands: "cpio," "link, unlink," "ln," and "mv, move."
Processed November 8, 1990 CP, COPY(1,C) 3