File operation patterns

From Tibsfox/gsd-skill-creator · View interactive version

File operation patterns is an AI agent skill from the GitHub repository Tibsfox/gsd-skill-creator. Safe file operation patterns. Use when performing bulk file operations or writing deployment scripts.

How to use this skill

Skill file

File Operation Patterns

Safe Patterns

# 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 |

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.