Skip to content

The cp command

Copy files and directories. Copies SOURCE to DEST. If the last name is an existing directory, the copies go inside it and keep their names. Copying a directory needs -r. An existing file at DEST is overwritten without asking.

Usage

cp [OPTION]... SOURCE DEST
cp [OPTION]... SOURCE... DIRECTORY

Options

-r, -R, --recursivecopy directories and everything in them
-v, --verbosesay what was copied

Examples

  • cp report.txt report-backup.txtA copy with a new name
  • cp *.jpg photos/Copy several files into a folder
  • cp -r website website-oldCopy a whole folder

Learn it step by step

learner@sandbox: ~bash (practice)
Note: Try cp here: your home directory has sample files. Press Try beside an example, or type your own.

A practice shell in your browser that behaves like bash on Linux for these commands. Nothing you type leaves the page.