File Management
by @tyronecoh
Perform safe file and directory operations on Unix systems using built-in tools for listing, searching, reading, organizing, and managing without external bi...
clawhub install file-managementπ About This Skill
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 backupls -la before touching anythingtrash (macOS) or rm as last resortBuilt-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 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
# Basic listing
ls -la /path/to/dirHuman-readable sizes, newest first
ls -lahF /path/to/dir | sort -k5 -rhRecursive depth
find /path -maxdepth 2 -type fShow hidden files
ls -la /path/to/dir
Search for Files by Name
# Find by name pattern
find /path -name "*.txt" -type fCase-insensitive
find /path -iname "readme*"Modified in last N days
find /path -name "*.md" -mtime -7By size
find /path -size +100M
Search File Contents
# Grep with context
grep -rn "search_term" /pathCase-insensitive
grep -ri "search_term" /pathOnly filenames with matches
grep -rl "search_term" /path
Disk Usage Analysis
# Total size of directory
du -sh /path/to/dirPer-subdirectory breakdown
du -h --max-depth=1 /path | sort -rhFind largest files (recursive)
find /path -type f -exec du -h {} + | sort -rh | head -20
Move / Copy / Delete
# Move (rename)
mv source.txt /new/path/Copy (recursive for directories)
cp -r /source/dir /dest/dirDelete β ALWAYS confirm first
Preferred on macOS (goes to Trash):
trash /path/to/file.txt
Or rm as last resort:
rm /path/to/file.txt
Batch Rename (pure bash)
# Rename all .txt to .md in current directory
for f in *.txt; do mv "$f" "${f%.txt}.md"; doneReplace spaces with underscores
for f in *\ *; do mv "$f" "${f// /_}"; done
Archive & Compress
# Create tar.gz
tar -czvf archive.tar.gz /pathExtract
tar -xzvf archive.tar.gzCreate zip
zip -r archive.zip /pathExtract zip
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:
1. Show what will be affected first
2. Ask for confirmation with exact command
3. Prefer trash over rm on macOS
Anti-Patterns (Never Do)
rm -rf / or any recursive delete without confirmingchmod -R 777 or permission changes that break securitysudo operations unless explicitly requestedQuick Reference
# Where am I?
pwdWhat's in current directory?
ls -laFind all PDFs larger than 10MB
find ~ -name "*.pdf" -size +10MHow much space is used?
du -sh ~/LibrarySearch for TODO in code files
grep -rn --include="*.py" "TODO" ~/code/