| name | file-operation-patterns |
| description | Safe file operation patterns. Use when performing bulk file operations or writing deployment scripts. |
| version | 1.0.0 |
| format | "2025-10-02T00:00:00.000Z" |
| triggers | ["performing bulk file operations or writing deployment scripts"] |
| updated | "2026-04-25T00:00:00.000Z" |
| status | ACTIVE |
File Operation Patterns
Safe Patterns
mkdir -p path/to/nested/dir
cp -rp src/ dst/
tmpfile=$(mktemp "${target}.XXXXXX")
echo "$content" > "$tmpfile"
mv "$tmpfile" "$target"
[ -n "$DIR" ] && [ "$DIR" != "/" ] && rm -rf "$DIR"
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 |