Linux for Developers
/Beginner
cp
Definition
Copy. The command used to copy files or directories from a source location to a destination location.
Explain Like I'm New
Copy and Paste. You duplicate a file, leaving the original perfectly intact.
Real World Example
Before editing a dangerous system file, you make a backup by typing `cp config.txt config.txt.backup`. Now you have two identical files.
Common Use Cases
- •Backing up files
- •Duplicating templates
Crucial Command Flags
| Flag / Option | Description |
|---|---|
| -r / -R | Recursive. Copy directories and their contents. |
| -i | Interactive. Prompt before overwrite. |
| -v | Verbose. Explain what is being done. |
| -p | Preserve. Keep original file attributes (time, ownership). |
Interview Questions
basic
- What happens if the destination file you are copying to already exists?
intermediate
- Why does `cp folder1 folder2` throw an 'omitting directory' error?