cp copies a file. Type the file you want to copy, then where the copy should go: a folder, or a new file name.
Every command and output on this page is real, run in Terminal with zsh 5.9 on macOS 26.
Syntax
cp source target
source: the file to copy.target: a folder, where the copy keeps its name, or a new file name for the copy.
See cp (opens in a new tab) in the POSIX standard.
The Example
A file named monday.txt and a folder named archive, side by side.
Step 1: Copy a File into a Folder
cp monday.txt archive/
cp prints nothing when it works. List the folder to see the copy:
ls archive
monday.txt
Step 2: Copy a File to a New Name
cp monday.txt monday-copy.txt
ls
archive monday-copy.txt monday.txt
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Copying a folder, such as cp notes archive/ | cp: notes is a directory (not copied). | Copy the files in it instead, such as cp notes/monday.txt archive/ |
FAQ
Does the original file change?
No. cp makes a copy and leaves the original where it was.
Conclusion
Type cp, the file and where it goes. A folder keeps the file’s name; a file name gives the copy a new one.
Additional Resources
- cp (opens in a new tab) (POSIX standard)
macOS is a trademark of Apple Inc.
0 comments