Skip to main content
0 reactions

How to Copy a File in the Terminal with cp

Card titled cp in the Terminal, labelled shell basics, with three ticked lines: cp monday.txt archive/, then ls archive, which shows monday.txt.

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

SyntaxBash
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

TerminalBash
cp monday.txt archive/

cp prints nothing when it works. List the folder to see the copy:

TerminalBash
ls archive
OutputPlain text
monday.txt

Step 2: Copy a File to a New Name

TerminalBash
cp monday.txt monday-copy.txt
TerminalBash
ls
OutputPlain text
archive         monday-copy.txt monday.txt

Common Mistakes

MistakeWhat happensDo 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

macOS is a trademark of Apple Inc.

0 comments