cp
PURPOSE
Copies files.
SYNOPSIS
cp file1 [ file2 ... ] target
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, then the files are copied
to that directory with the same file name.
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 and that data is copied into a regular
file.
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 subdi-
rectories do not exist, the system creates them.
FLAGS
-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, then 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 direc-
tory:
cp prog.c prog.bak
This copies "prog.c" to "prog.bak". If the file
"prog.bak" does not already exist, then cp creates
it. If it does exist, then cp replaces it with a
copy of "prog.c".
2. To copy a file to another directory:
cp jones /u/nick/clients
This copies "jones" to "/u/nick/clients/jones".
3. To copy a file to a new file and preserve the modifi-
cation date and time:
cp -p smith smith.jr
This copies "smith" to "smith.jr". Instead of cre-
ating the file with the current date and time stamp,
the system gives "smith.jr" the same date and time as
"smith".
4. To copy all the files in a directory to a new direc-
tory:
cp /u/nick/clients /u/nick/customers
This copies the files in the directory "clients" to
the directory "customers".
5. To copy the files and subdirectories in a directory
to another directory:
cp -r /u/nick/clients /u/nick/customers
This copies the files, subdirectories, and files in
the subdirectories rooted at the directory "clients"
to the directory "customers".
6. To copy a specific set of files to another directory:
cp jones lewis smith /u/nick/clients
This copies "jones, lewis," and "smith" to
"/u/nick/clients".
7. To use pattern-matching characters to copy files:
cp programs/*.c .
This copies the files in directory "programs" that
end with ".c" to the current directory (.). You must
type a space between the "c" and the final period.
RELATED INFORMATION
The following commands: "cpio," "link, unlink," "ln,"
and "mv."