cp
Copy files and directories from one location to another.
Synopsis
cp [OPTION]... SOURCE... DEST
Examples
cp file.txt backup.txt
cp -r src/ dest/
cp -iv *.log /tmp/
cp -a /data /backup/data
Common options
| Flag | Description |
|---|---|
| -r, -R | Copy directories recursively |
| -i | Prompt before overwrite |
| -v | Verbose — explain what is being done |
| -p | Preserve mode, ownership, and timestamps |
| -u | Copy only when source is newer than destination |
About cp
The `cp` command copy files and directories from one location to another. File operation commands are essential for navigating and managing the Linux filesystem.
They form the backbone of everyday system administration and development workflows. Mastering these commands enables you to efficiently create, move, copy, and organize files and directories from the terminal, which is often faster and more scriptable than graphical alternatives.
The command accepts 5 commonly used flags shown above, though the full set of options is available in the man page (`man cp`). The 4 examples on this page cover typical real-world usage patterns that you can copy and adapt for your own workflows.
Related commands
More File Operations Commands
Other commands in the File Operations category