cp command
Copy files and directories.
- Files & directories
- Package coreutils
- 8 options · 7 examples
Syntax
cp [options] source… destinationProvided by the coreutils package. Run man cp for the full manual.
Common options
| Option | What it does |
|---|---|
-r | Copy directories recursively |
-a | Archive: recursive, keep permissions, owners, times and links |
-i | Ask before overwriting |
-n | Never overwrite existing files |
-u | Copy only when the source is newer |
-v | Print each file copied |
-p | Keep mode, ownership and timestamps |
--parents | Recreate the source path under the destination |
Examples
Copy a file
cp file.txt /tmp/Copy and rename
cp config.yml config.yml.bakCopy a directory
cp -r project/ /backup/Copy and keep permissions and times
cp -a /var/www /backup/wwwAsk before overwriting
cp -i *.conf /etc/app/Copy only newer files
cp -u src/* dest/Keep the directory path
cp --parents src/app/main.c /backup/
No example matches. Check the options table or search the guides.
Tips
- For large or remote copies,
rsync -acan resume and shows progress.
cp guides
- How to Preserve Directory Path with CP Command Linux Commands · Updated Apr 2025
- The `cp` Command in Linux (Copy Files) Linux Commands · Updated Apr 2025
