How to copy files

Overview

cp creates a duplicate and leaves the source in place. The final argument is normally the destination.

Examples

cp notes.txt notes-backup.txt
cp notes.txt ~/Documents/
cp *.txt backups/
cp -r project project-copy

Useful options

  • -i asks before replacing an existing destination
  • -v prints each copy operation
  • -r recursively copies a directory
  • -a preserves links, permissions, timestamps, and structure
  • -n avoids overwriting existing files

Tips and safety

Use cp -i while learning and list the destination afterward. A trailing slash can clarify that the destination is a directory.

For large or resumable backups, rsync -a is often preferable after you understand basic copying.