$cp
Copy files and directories to a destination path.
cp [OPTIONS] SOURCE... DESTTry `cp` Live in Interactive Sandbox
Zero-install client simulation with real-time feedback.
Overview & How cp Works
`cp` (Copy) duplicates files or folders from a source to a destination. It supports copying single files, multiple files into target directories, and recursive directory tree replication with preservation of file modes and timestamps.
Common Flags & Command Options
| Flag / Option | Description |
|---|---|
| -r, -R | Copy directories and their contents recursively. |
| -p | Preserve specified attributes like mode, ownership, and timestamps. |
| -a | Archive mode (same as -dR --preserve=all) for exact backups. |
| -u | Copy only when the SOURCE file is newer than the destination file. |
| -v | Verbose output showing files as they are copied. |
Practical Real-World Examples
cp welcome.txt welcome.txt.bak && ls -lDuplicates welcome.txt into welcome.txt.bak in the same directory.
Frequently Asked Questions
What is the best flag to back up an entire folder preserving permissions?
Use `cp -a [source] [destination]` (Archive mode) to preserve permissions, ownership, symlinks, and timestamps.
Related Linux Commands
Search for files and directories in a directory hierarchy based on name, type, size, or modification date.
Concatenate and print file contents directly to the terminal standard output.
Create new directories and folder hierarchies.
Remove files or directories from the filesystem.
Move or rename files and directories.
Create empty files or update file access and modification timestamps.