cp
cp [OPTION]... [-T] SOURCE DEST
cp [OPTION]... SOURCE... DIRECTORY
cp [OPTION]... -t DIRECTORY SOURCE...
Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.
Options
--target-directory=<target-directory>
,-t <target-directory>
-
copy all SOURCE arguments into target-directory
--no-target-directory
,-T
-
Treat DEST as a regular file and not a directory
--interactive
,-i
-
ask before overwriting files
--link
,-l
-
hard-link files instead of copying
--no-clobber
,-n
-
don't overwrite a file that already exists
--recursive
,-R
,-r
-
copy directories recursively
--strip-trailing-slashes
-
remove any trailing slashes from each SOURCE argument
--debug
-
explain how a file is copied. Implies -v
--verbose
,-v
-
explicitly state what is being done
--symbolic-link
,-s
-
make symbolic links instead of copying
--force
,-f
-
if an existing destination file cannot be opened, remove it and try again (this option is ignored when the -n option is also used). Currently not implemented for Windows.
--remove-destination
-
remove each existing destination file before attempting to open it (contrast with --force). On Windows, currently only works for writeable files.
--backup=<CONTROL>
-
make a backup of each existing destination file
-b
-
like --backup but does not accept an argument
--suffix=<SUFFIX>
,-S <SUFFIX>
-
override the usual backup suffix
--update
-
move only when the SOURCE file is newer than the destination file or when the destination file is missing
-u
-
like --update but does not accept an argument
--reflink=<WHEN>
-
control clone/CoW copies. See below
--attributes-only
-
Don't copy the file data, just the attributes
--preserve=<ATTR_LIST>
-
Preserve the specified attributes (default: mode, ownership (unix only), timestamps), if possible additional attributes: context, links, xattr, all
--preserve-default-attributes
,-p
-
same as --preserve=mode,ownership(unix only),timestamps
--no-preserve=<ATTR_LIST>
-
don't preserve the specified attributes
--parents
-
use full source file name under DIRECTORY
--no-dereference
,-P
-
never follow symbolic links in SOURCE
--dereference
,-L
-
always follow symbolic links in SOURCE
-H
-
follow command-line symbolic links in SOURCE
--archive
,-a
-
Same as -dR --preserve=all
-d
-
same as --no-dereference --preserve=links
--one-file-system
,-x
-
stay on this file system
--sparse=<WHEN>
-
control creation of sparse files. See below
--copy-contents
-
NotImplemented: copy contents of special files when recursive
--context=<CTX>
-
NotImplemented: set SELinux security context of destination file to default type
--progress
,-g
-
Display a progress bar.
Note: this feature is not supported by GNU coreutils.
Do not copy a non-directory that has an existing destination with the same or newer modification timestamp;
instead, silently skip the file without failing. If timestamps are being preserved, the comparison is to the
source timestamp truncated to the resolutions of the destination file system and of the system calls used to
update timestamps; this avoids duplicate work if several cp -pu
commands are executed with the same source
and destination. This option is ignored if the -n
or --no-clobber
option is also specified. Also, if
--preserve=links
is also specified (like with cp -au
for example), that will take precedence; consequently,
depending on the order that files are processed from the source, newer files in the destination may be replaced,
to mirror hard links in the source. which gives more control over which existing files in the destination are
replaced, and its value can be one of the following:
all
This is the default operation when an--update
option is not specified, and results in all existing files in the destination being replaced.none
This is similar to the--no-clobber
option, in that no files in the destination are replaced, but also skipping a file does not induce a failure.older
This is the default operation when--update
is specified, and results in files being replaced if they’re older than the corresponding source file.
Examples
Copy a file to another location:
cp {{path/to/source_file.ext}} {{path/to/target_file.ext}}
Copy a file into another directory, keeping the filename:
cp {{path/to/source_file.ext}} {{path/to/target_parent_directory}}
Recursively copy a directory's contents to another location (if the destination exists, the directory is copied inside it):
cp -R {{path/to/source_directory}} {{path/to/target_directory}}
Copy a directory recursively, in verbose mode (shows files as they are copied):
cp -vR {{path/to/source_directory}} {{path/to/target_directory}}
Copy multiple files at once to a directory:
cp -t {{path/to/destination_directory}} {{path/to/file1 path/to/file2 ...}}
Copy text files to another location, in interactive mode (prompts user before overwriting):
cp -i {{*.txt}} {{path/to/target_directory}}
Follow symbolic links before copying:
cp -L {{link}} {{path/to/target_directory}}
Use the first argument as the destination directory (useful for xargs ... | cp -t <DEST_DIR>
):
cp -t {{path/to/target_directory}} {{path/to/file_or_directory1 path/to/file_or_directory2 ...}}
The examples are provided by the tldr-pages project under the CC BY 4.0 License.
Please note that, as uutils is a work in progress, some examples might fail.