cp
Make a copy of a file, copy several files into a folder, or copy a whole folder with -r.
>_ Try it: a simulated Linux, right herenothing runs on your computer
Loading the terminal…
Examples
-
cp todo.txt todo.bak -
mkdir backup -
cp -v todo.txt ideas.txt backup/ -
cp -r backup backup-2 -
ls backup-2 -
cp -n ideas.txt todo.txt
How it works
cp SOURCE DEST copies a file. If DEST is a folder that exists, the copy goes inside it with the same name; otherwise DEST is the new name.
Folders need -r (recursive): cp -r project project-backup copies the folder and everything in it. Careful: cp overwrites an existing file without asking, unless you add -n.
Syntax
cp [OPTION]... SOURCE... DEST
Options
| Option | What it does |
|---|---|
-r | copy folders and everything inside them |
-v | say what was copied |
-n | never overwrite a file that already exists |
Good to know
- To copy several files, the last name must be a folder:
cp a.txt b.txt backup/. - A copy is a new file: changing
todo.baklater doesn't touchtodo.txt.