Command library / cp
cp
Copy files and directories
Copies a file (or, with -r, an entire directory tree) to a new location. The source comes first, the destination second — get that backwards and you copy the wrong thing over the wrong thing.
Practice cpUsage
Options and flags
sourcefile or directory to copy
destinationwhere to put the copy
-r, -Rrecursive: required to copy a directory
-vverbose: print each file as it's copied
-iinteractive: ask before overwriting an existing file
-ppreserve mode, ownership and timestamps
Examples
cp report.txt backup/report.txtCopy one file into a backup folder.
cp -r project/ project-backup/Copy an entire directory tree.
cp -v config.yml config.yml.bakMake a quick backup copy, printing confirmation.
cp -i secrets.env /tmp/secrets.envCopy but ask first if the destination already exists.
Common mistakes
cp needs both a source AND a destination — it never guesses where the copy should go.
Copying a directory without -r fails with 'omitting directory' — the recursive flag is required for folders.