file-operations
Production-grade file operations - permissions, find, archives, rsync
What this skill does
# File Operations Skill
> Master file system operations with production-ready patterns
## Learning Objectives
After completing this skill, you will be able to:
- [ ] Manage file permissions (chmod, chown)
- [ ] Search files efficiently with find and fd
- [ ] Create and extract archives (tar, zip)
- [ ] Synchronize files with rsync
- [ ] Work with symbolic and hard links
## Prerequisites
- Bash basics
- Understanding of file systems
- Command line navigation
## Core Concepts
### 1. Permission Management
```bash
# Numeric notation
chmod 755 script.sh # rwxr-xr-x
chmod 644 file.txt # rw-r--r--
chmod 600 secret.key # rw-------
# Symbolic notation
chmod u+x script.sh # Add execute for owner
chmod g-w file.txt # Remove write for group
chmod a+r public.txt # Add read for all
# Ownership
chown user:group file
chown -R user:group dir/
# Common patterns
chmod 600 ~/.ssh/id_rsa # SSH private key
chmod 755 /var/www/html/ # Web directory
```
### 2. Find Command
```bash
# By name
find . -name "*.txt"
find . -iname "*.TXT" # Case insensitive
# By type
find . -type f # Files
find . -type d # Directories
find . -type l # Symlinks
# By size/time
find . -size +100M # Larger than 100MB
find . -mtime -7 # Modified in 7 days
# Actions
find . -name "*.tmp" -delete
find . -type f -exec chmod 644 {} +
```
### 3. Archive Operations
```bash
# Create archives
tar -cvf archive.tar dir/
tar -czvf archive.tar.gz dir/ # gzip
tar -cjvf archive.tar.bz2 dir/ # bzip2
# Extract archives
tar -xvf archive.tar
tar -xzvf archive.tar.gz -C /dest/
# ZIP
zip -r archive.zip dir/
unzip archive.zip
```
### 4. Rsync
```bash
# Local sync
rsync -avz source/ dest/
# Remote sync
rsync -avz local/ user@host:/remote/
# With delete (mirror)
rsync -avz --delete source/ dest/
# Dry run
rsync -avzn source/ dest/
```
## Common Patterns
### Safe Delete Pattern
```bash
# With confirmation
rm -i file.txt
# With variable check
rm -rf "${DIR:?}/" # Fails if DIR empty
```
### Backup Pattern
```bash
# Timestamped backup
backup() {
local src="$1"
local timestamp=$(date +%Y%m%d_%H%M%S)
cp -a "$src" "${src}.${timestamp}.bak"
}
```
### Find and Process
```bash
# Fix permissions
find /var/www -type d -exec chmod 755 {} +
find /var/www -type f -exec chmod 644 {} +
# Delete old files
find /tmp -type f -mtime +7 -delete
```
## Anti-Patterns
| Don't | Do | Why |
|-------|-----|-----|
| `rm -rf $VAR/` | `rm -rf "${VAR:?}/"` | Empty VAR = delete / |
| `find \| xargs rm` | `find -delete` | Handles spaces |
| `cp -r` for sync | `rsync -a` | rsync is smarter |
## Practice Exercises
1. **Permission Fixer**: Script to fix web dir permissions
2. **Old File Cleaner**: Remove files older than N days
3. **Backup Script**: Timestamped backup with rotation
4. **Sync Tool**: Two-way directory sync
## Troubleshooting
### Common Errors
| Error | Cause | Fix |
|-------|-------|-----|
| `Permission denied` | Wrong permissions | Check with `ls -la` |
| `No such file` | Path typo | Verify path exists |
| `Directory not empty` | rm without -r | Add `-r` flag |
| `Cross-device link` | Hard link across fs | Use symlink |
### Debug Techniques
```bash
# Check permissions
stat file.txt
ls -la file.txt
# Trace find
find . -name "*.txt" -print
# Dry-run rsync
rsync -avzn source/ dest/
```
## Safety Guidelines
1. **Always dry-run** rsync with `--delete` first
2. **Quote paths** with spaces: `"$path"`
3. **Verify paths** before `rm -rf`
4. **Use trash** instead of rm when possible
5. **Backup** before bulk operations
## Resources
- [GNU Coreutils](https://www.gnu.org/software/coreutils/manual/)
- [find Manual](https://www.gnu.org/software/findutils/manual/)
- [rsync Manual](https://rsync.samba.org/documentation.html)
- [fd - modern find](https://github.com/sharkdp/fd)
Related in General
modeling-omnistudio-epc-catalog
IncludedSalesforce Industries CME EPC product-modeling skill for Product2-based catalog creation. Use when creating EPC products, configuring product attributes, building offer bundles with Product Child Items, or reviewing EPC DataPack JSON metadata for product catalog changes. TRIGGER when: user creates or updates Product2 EPC records, AttributeAssignment payloads, AttributeMetadata/AttributeDefaultValues, Offer bundles, or ProductChildItem relationships. DO NOT TRIGGER when: designing OmniScripts/FlexCards/Integration Procedures (use building-omnistudio-omniscript, building-omnistudio-flexcard, or building-omnistudio-integration-procedure), implementing Apex business logic (use generating-apex), or troubleshooting deployment pipelines (use deploying-metadata).
relationship-science-coach
IncludedUse this skill for direct, practical adult relationship coaching: couples conflict, repair, trust, marriage, dating, flirting, attachment patterns, emotional connection, sex, desire differences, eroticism, kink negotiation, affection, love languages, breakups, and long-term passion. Draw on Gottman, EFT and Hold Me Tight, attachment science, modern sex research, Perel, Nagoski, Kerner, Schnarch, Love and Stosny, and flexible love-language tools. Be concrete and low-hedge. Redirect only for imminent danger, abuse, coercive control, minors, non-consent, self-harm, stalking, or medical/legal/psychiatric decisions.
building-sf-integrations
IncludedSalesforce integration architecture and runtime plumbing with 120-point scoring. Use this skill to set up Named Credentials, External Credentials, External Services, REST/SOAP callout patterns, Platform Events, and Change Data Capture. TRIGGER when: user sets up Named Credentials, External Services, REST/SOAP callouts, Platform Events, CDC, or touches .namedCredential-meta.xml files. DO NOT TRIGGER when: Connected App/OAuth config (use configuring-connected-apps), Apex-only logic (use generating-apex), or data import/export (use handling-sf-data).
venue-templates
IncludedAccess comprehensive LaTeX templates, formatting requirements, and submission guidelines for major scientific publication venues (Nature, Science, PLOS, IEEE, ACM), academic conferences (NeurIPS, ICML, CVPR, CHI), research posters, and grant proposals (NSF, NIH, DOE, DARPA). This skill should be used when preparing manuscripts for journal submission, conference papers, research posters, or grant proposals and need venue-specific formatting requirements and templates.
let-fate-decide
IncludedDraws the 12 Houses of the Zodiac Tarot spread to inject entropy into planning when prompts are vague, ambiguous, or casually delegated. Interprets the spread to guide next steps. Use when the user says 'let fate decide', 'YOLO', 'whatever', 'idk', or other nonchalant phrases, makes Yu-Gi-Oh references, or when you are about to arbitrarily pick between multiple reasonable approaches. Prefer over ask-questions-if-underspecified when the user's tone is casual or playful rather than precision-seeking.
net-ops
IncludedCross-platform network troubleshooting (Windows, macOS, Linux) via local or remote shell. Use for: DNS broken, can't resolve hostnames, nslookup/dig works but apps fail, NRPT, WFP, scutil, /etc/resolver, systemd-resolved, /etc/resolv.conf, NetworkManager, VPN DNS leak residue (ProtonVPN/Mullvad/WireGuard/AnyConnect), AV/firewall blocking DNS or DoH, Tailscale DNS interaction, intermittent connectivity, remote diagnostics over SSH.