Skip to content

cp command

Copy files and directories.

On this page

Syntax

cp [options] source… destination

Provided by the coreutils package. Run man cp for the full manual.

Common options

OptionWhat it does
-rCopy directories recursively
-aArchive: recursive, keep permissions, owners, times and links
-iAsk before overwriting
-nNever overwrite existing files
-uCopy only when the source is newer
-vPrint each file copied
-pKeep mode, ownership and timestamps
--parentsRecreate the source path under the destination

Examples

  1. Copy a file

    cp file.txt /tmp/
  2. Copy and rename

    cp config.yml config.yml.bak
  3. Copy a directory

    cp -r project/ /backup/
  4. Copy and keep permissions and times

    cp -a /var/www /backup/www
  5. Ask before overwriting

    cp -i *.conf /etc/app/
  6. Copy only newer files

    cp -u src/* dest/
  7. Keep the directory path

    cp --parents src/app/main.c /backup/

Tips

  • For large or remote copies, rsync -a can resume and shows progress.

cp guides

← All Linux commands · Suggest a fix

Back to top