Agent skill

file-operation-patterns

Safe file operation patterns. Use when performing bulk file operations or writing deployment scripts.

Stars 163
Forks 31

Install this agent skill to your Project

npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/other/file-operation-patterns-tibsfox-gsd-skill-creator

SKILL.md

File Operation Patterns

Safe Patterns

bash
# Create directory tree (idempotent)
mkdir -p path/to/nested/dir

# Copy preserving permissions
cp -rp src/ dst/

# Atomic write (prevents partial reads)
tmpfile=$(mktemp "${target}.XXXXXX")
echo "$content" > "$tmpfile"
mv "$tmpfile" "$target"

# Safe deletion (guard variables)
[ -n "$DIR" ] && [ "$DIR" != "/" ] && rm -rf "$DIR"

# Incremental sync
rsync -av src/ dst/

Anti-Patterns

Don't Do
rm -rf $DIR unguarded Guard with [ -n "$DIR" ]
Write directly to target Write to temp, then mv
Assume dir exists mkdir -p first
Ignore permissions cp -p or explicit chmod

Expand your agent's capabilities with these related and highly-rated skills.

Didn't find tool you were looking for?

Be as detailed as possible for better results