When to use cp
Use cp for a one-time file or directory copy on the server. Check whether the destination exists first: an existing directory and a new filename produce different layouts, especially when copying backups.
Syntax
cp [PARAMETERS] SOURCE DESTINATIONSquare brackets mark optional arguments; an ellipsis means repetition. Replace example file names, user names and server addresses with your own values.
Common options and arguments
Usage examples
Copy configuration
cp -i app.conf app.conf.bakAn existing backup triggers a confirmation before replacement; a new backup is created without a prompt.
Copy directory
cp -a ./project ./project-backupArchive mode copies the directory tree and attempts to preserve attributes; inspect the destination layout afterward.
Copy file to directory
cp report.txt ./archive/The archive directory must already exist; the copied file retains its basename.
Notes and limitations
- If the name matches, the destination file may be overwritten; to check use -i.
- cp works with the local file system of the server; for another host use scp or rsync.
Common questions and troubleshooting
Why does cp skip a directory?
Directory copying requires recursion. Use archive mode when preserving attributes matters and verify that the account can read every source file.
Is cp an incremental backup?
It does not provide backup version history or a retention policy. Keep independent dated backups and consider rsync when you need repeatable synchronization.
Further help
Options vary by version and distribution. Check the installed documentation with this command: man cp.