cp: copy files and directories

Updated November 2026

cp copies files. With -r it copies whole directory trees, and with -a it keeps permissions, owners and times exactly as they were.

cp [options] source target cp [options] source ... directory

Common options

OptionMeaning
-r, -RCopy directories recursively
-aArchive: recursive, keep permissions, owners, times and links (GNU, BSD, macOS)
-pKeep mode, owner and timestamps
-iAsk before overwriting
-nNever overwrite an existing file
-uCopy only when the source is newer (GNU)
-vShow each file as it is copied
-LFollow symbolic links and copy what they point to

Examples

cp notes.txt notes.bak                  # copy a file
cp report.pdf ~/Documents/              # copy into a directory
cp *.jpg /srv/photos/                   # many files into a directory
cp -r project project-copy              # copy a directory tree
cp -a /etc /root/etc-backup             # exact copy, keeping owners and permissions
cp -i config.yml /etc/app/              # ask before overwriting
cp --backup=numbered app.conf /etc/app/ # keep the old file as app.conf.~1~ (GNU)

Things to know