CtrlK
BlogDocsLog inGet started
Tessl Logo

cp

Copy files and directories. Use when duplicating files, creating backups, or copying directory trees with preserved attributes.

69

Quality

84%

Does it follow best practices?

Impact

No eval scenarios have been run

SecuritybySnyk

Passed

No known issues

SKILL.md
Quality
Evals
Security

cp - Copy Files and Directories

Synopsis

cp [OPTION]... SOURCE DEST
cp [OPTION]... SOURCE... DIRECTORY

Copy SOURCE to DEST, or multiple SOURCEs to DIRECTORY.

Flags

FlagLong FormDescription
-r, -R--recursiveCopy directories recursively
-a--archiveSame as -dR --preserve=all (preserve everything)
-pSame as --preserve=mode,ownership,timestamps
--preserve[=ATTR_LIST]Preserve attributes: mode, ownership, timestamps, context, links, xattr, all
--no-preserve=ATTR_LISTDon't preserve specified attributes
-dSame as --no-dereference --preserve=links
-i--interactivePrompt before overwrite
-n--no-clobberDo not overwrite existing files
-f--forceRemove existing destination file if needed
-u--updateCopy only when SOURCE is newer or DEST missing
-l--linkHard link files instead of copying
-s--symbolic-linkMake symbolic links instead of copying
-L--dereferenceAlways follow symlinks in SOURCE
-P--no-dereferenceNever follow symlinks in SOURCE
-HFollow symlinks on command line only
-bMake backup of each existing destination file
--backup[=CONTROL]Make backup: none, off, numbered, t, existing, nil, simple, never
-S--suffix=SUFFIXOverride backup suffix (default ~)
-t--target-directory=DIRCopy all SOURCE args into DIR
-T--no-target-directoryTreat DEST as normal file, not directory
-v--verboseExplain what is being done
--reflink[=WHEN]Control copy-on-write: always, auto, never
--sparse=WHENControl sparse files: auto, always, never
--strip-trailing-slashesRemove trailing slashes from SOURCE
-x--one-file-systemStay on this file system
--helpDisplay help
--versionOutput version

Examples

# Copy a file
cp source.txt dest.txt

# Copy directory recursively
cp -r srcdir/ dstdir/

# Archive copy (preserve all attributes)
cp -a srcdir/ dstdir/

# Copy with backup
cp --backup=numbered file.txt /dest/

# Don't overwrite existing files
cp -n source.txt dest.txt

# Copy only newer files
cp -u source.txt dest.txt

# Interactive (prompt before overwrite)
cp -i source.txt dest.txt

# Verbose copy
cp -rv srcdir/ dstdir/

# Copy multiple files to a directory
cp file1.txt file2.txt /dest/dir/

# Create hard links instead of copying
cp -l file.txt link.txt

# Copy-on-write (fast, deferred copy on supporting fs)
cp --reflink=auto large_file.img copy.img

Gotchas

  • Forgetting -r for directories is the most common mistake. Without it, cp silently skips directories or errors out.
  • -a is almost always what you want for directory copies (preserves permissions, symlinks, timestamps).
  • cp -r dir1 dir2 when dir2 exists creates dir2/dir1/. Use cp -r dir1/ dir2/ or -T flag to control this.
  • -n and -i behavior: -n silently skips, -i prompts. If both are given, -n takes precedence.
  • --reflink=auto is a performance win on CoW filesystems (btrfs, APFS, XFS with reflink). Falls back to regular copy otherwise.
Repository
flox/floxenvs
Last updated
Created

Is this your skill?

If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.