cp
Files
SKILL.mdagentsreferences
Install
Install the containing plugin
/plugin install shared-skills@llm-skills
Invoke this skill after installation
/shared-skills:cp
This skill is bundled inside shared-skills. Install the plugin once, then Claude Code can use any of its included skills. Browse the full plugin repository at github.com/alisonaquinas/llm-shared-skills.
SKILL.md
name: cp description: > Copy files and directories with cp for duplicating, backing up, and distributing content. Use when the agent needs to copy a single file, recursively copy a directory tree, preserve metadata and permissions, avoid overwriting newer files, or create a backup before modifying the original.
cp
Copy files and directories with control over overwrite behaviour, metadata preservation, and backup creation.
Quick Start
- Verify availability:
cp --version(GNU) orman cp - Copy a file:
cp source.txt destination.txt - Recursively copy a directory:
cp -r src/ dest/
Intent Router
references/cheatsheet.md— Common flags, recursive copy, metadata preservation, overwrite controlreferences/advanced-usage.md— Archive mode, backup suffixes, sparse files, reflinks, progress reportingreferences/troubleshooting.md— Permission errors, cross-filesystem issues, symlink handling, silent overwrites
Core Workflow
- Confirm source path and destination intent before running
- Use
-i(interactive) or-n(no-clobber) to protect against silent overwrites - Use
-rfor directories; add-a(archive) to also preserve permissions, timestamps, and symlinks - Verify the copy with
difforls -lon both sides - Clean up the original only after confirming the copy is intact
Quick Command Reference
cp source.txt dest.txt # Copy a single file
cp -r src/ dest/ # Recursively copy directory
cp -a src/ dest/ # Archive: preserves permissions, times, symlinks
cp -i source.txt dest.txt # Prompt before overwriting
cp -n source.txt dest.txt # Never overwrite existing files
cp -u source.txt dest.txt # Copy only when source is newer
cp -v source.txt dest.txt # Verbose: print each file copied
cp -p source.txt dest.txt # Preserve mode, ownership, timestamps
cp --backup=numbered source.txt d/ # Create numbered backups of overwritten files
cp -r --preserve=all src/ dest/ # Copy tree preserving all metadata (GNU)
man cp # Full manual
Safety Notes
| Area | Guardrail |
|---|---|
| Silent overwrite | By default cp overwrites the destination without warning. Use -i interactively or -n in scripts to prevent data loss. |
| Directory trailing slash | cp -r src dest behaves differently depending on whether dest exists. If dest exists, src is copied inside it. If not, dest is created as the copy. Verify intent before running. |
| Permissions | Without -p or -a, copied files inherit the umask of the current process. Use -a or --preserve when permissions must match the source. |
| Symlinks | By default cp follows symlinks and copies the referenced file. Use -P (or -d) to copy the symlink itself. |
| Cross-filesystem | Hardlinks are silently converted to copies. Use rsync -aH to preserve hardlinks across filesystems. |
| Disk space | Verify available space before copying large trees. df -h and du -sh src/ are useful pre-flight checks. |
Source Policy
- Treat
man cpandcp --helpas runtime truth. GNU and BSDcpdiffer in some flags. - For large or critical copies, prefer
rsync— it supports resuming, checksums, and dry-run. - Always verify the result with
diff -rormd5sumfor integrity-sensitive copies.
See Also
$rsyncfor resumable, checksum-verified, and remote copies$mvfor moving instead of copying$lnfor creating aliases without duplicating data