name: file-management
description: Safe filesystem operations using built-in Unix tools and macOS utilities. Use when listing, searching, reading, organizing, or managing files and directories. Always confirm destructive operations before executing. Triggers on: "list files", "search for files", "find files", "organize files", "batch rename", "move files", "copy files", "delete files", "disk usage", "file search".
File Management
Safe filesystem operations using only pre-installed system tools. No external dependencies, no network access, no install.
Core Principle
Safety first — always confirm destructive operations before executing.
mv, cp, rm are irreversible without a backup
- Prefer
ls -la before touching anything
- For deletions, prefer
trash (macOS) or rm as last resort
Built-in Tools Only
Guaranteed on all Unix/macOS
| Tool | Purpose | Notes |
|---|
ls | List files | All Unix ✅ |
find | Search files | All Unix ✅ |
grep | Search file contents | All Unix ✅ |
cat / head / tail | Read files | All Unix ✅ |
mv | Move / rename | Write ⚠️ |
cp | Copy files | Write ⚠️ |
mkdir | Create directories | Write ⚠️ |
rm | Delete files | Write ⚠️ last resort |
stat | File metadata | All Unix ✅ |
du | Disk usage | All Unix ✅ |
tar | Archive files | All Unix ✅ |
xattr | Extended attributes | macOS ✅ |
macOS-specific (pre-installed)
| Tool | Purpose | Notes |
|---|
trash | Move to Trash (recoverable) | macOS ✅ preferred |
pbcopy / pbpaste | Clipboard | macOS ✅ |
mdls | Spotlight metadata | macOS ✅ |
mdutil | Spotlight index | macOS ✅ |
Optional tools (may not be installed)
These are helpful but NOT guaranteed. Check with which <tool> before using:
tree — directory tree view (install: brew install tree)
rg (ripgrep) — faster grep (install: brew install ripgrep)
fd — faster find (install: brew install fd)
dust — better du (install: brew install dust)
bat — better cat (install: brew install bat)
Common Patterns
List Directory Contents
ls -la /path/to/dir
ls -lahF /path/to/dir | sort -k5 -rh
find /path -maxdepth 2 -type f
ls -la /path/to/dir
Search for Files by Name
find /path -name "*.txt" -type f
find /path -iname "readme*"
find /path -name "*.md" -mtime -7
find /path -size +100M
Search File Contents
grep -rn "search_term" /path
grep -ri "search_term" /path
grep -rl "search_term" /path
Disk Usage Analysis
du -sh /path/to/dir
du -h --max-depth=1 /path | sort -rh
find /path -type f -exec du -h {} + | sort -rh | head -20
Move / Copy / Delete
mv source.txt /new/path/
cp -r /source/dir /dest/dir
trash /path/to/file.txt
rm /path/to/file.txt
Batch Rename (pure bash)
for f in *.txt; do mv "$f" "${f%.txt}.md"; done
for f in *\ *; do mv "$f" "${f// /_}"; done
Archive & Compress
tar -czvf archive.tar.gz /path
tar -xzvf archive.tar.gz
zip -r archive.zip /path
unzip archive.zip
Permission Model
Read-only operations — safe to execute without asking:
ls, find, grep, cat, head, tail, du, stat, file, mdls
Write operations — always confirm before executing:
mv, cp, mkdir, trash, rm, zip, tar
For destructive operations:
- Show what will be affected first
- Ask for confirmation with exact command
- Prefer
trash over rm on macOS
Anti-Patterns (Never Do)
- ❌
rm -rf / or any recursive delete without confirming
- ❌
chmod -R 777 or permission changes that break security
- ❌ Executing downloaded scripts directly without review
- ❌ Accessing paths outside user's home without asking
- ❌
sudo operations unless explicitly requested
Quick Reference
pwd
ls -la
find ~ -name "*.pdf" -size +10M
du -sh ~/Library
grep -rn --include="*.py" "TODO" ~/code/