cp Copy files and directories
Makes a copy of a file, or of several files, in another place. Add -R to copy whole folders. The original stays where it is.
Synopsis
cp [OPTION]... SOURCE TARGET
cp [OPTION]... SOURCE... DIRECTORY
Common options
| Option or form | What it does |
|---|---|
-R, -r | Copy a directory and everything inside it. Required for folders |
-i | Interactive: ask before overwriting an existing file |
-n | Do not overwrite an existing file |
-f | Force: replace existing files without asking |
-p | Preserve the modification time, permissions and, where allowed, owner of each file |
-v | Verbose: print each file as it is copied |
-a | Archive mode: copy a tree and keep attributes and symbolic links as they are (same as -RpP on macOS) |
Examples
cp notes.txt notes-backup.txt
cp notes.txt app.log docs
cp -R photos photos-backup
cp -pv data.csv data-copy.csv
cp -n notes.txt docs/notes.txt
cp -i report.pdf /backup/report.pdf
Notes
- cp overwrites the target without asking when it already exists and you have permission. Use -i to be asked, or -n to never overwrite.
- Copying a folder needs -R. Without it cp prints a message that the source is a directory and skips it.
- A trailing slash on the source differs between systems. On macOS, cp -R src/ dest copies the contents of src. On GNU/Linux, src and src/ are treated the same, and the folder itself is copied into dest if it exists. Check the result when moving a command between the two.
- On macOS -a means -RpP. GNU cp -a is a little different, so state the options you need if exact behaviour matters, for example -Rp.
- If the target is an existing folder, the file is copied inside it. If it is not, the target becomes the new file name. Add a trailing slash to the folder name to be sure it is treated as a folder.
See also
Last reviewed 2026-10-07.