Skip to content

cp

Copy files and directories.

Synopsis

tofu cp <source...> <destination> [flags]

Description

Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.

Flags

Flag Short Description Default
--recursive -r Copy directories recursively false
--force -f Remove destination file if cannot open, then retry false
--interactive -i Prompt before overwriting false
--no-clobber -n Do not overwrite an existing file false
--verbose -v Explain what is being done false
--preserve -p Preserve mode, ownership, and timestamps false

Examples

Copy a file:

tofu cp source.txt dest.txt

Copy file to directory:

tofu cp file.txt /path/to/directory/

Copy multiple files:

tofu cp file1.txt file2.txt /destination/

Copy directory recursively:

tofu cp -r source_dir/ dest_dir/

Preserve file attributes:

tofu cp -p important.txt backup.txt

Interactive mode:

tofu cp -i source.txt dest.txt

Verbose output:

tofu cp -v file.txt backup/
# Output: 'file.txt' -> 'backup/file.txt'