| name | personal-console-usage |
| description | Modern command-line tools for efficient file operations, searching, and bulk transformations. Use this skill whenever working with files at scale - searching, finding, replacing, or refactoring code. Prefer rg (ripgrep) for searching, fd for file discovery, sd for find-and-replace, and ast-grep for syntax-aware refactoring. Use parallel for concurrent operations on multiple files. This skill helps you work faster and more safely with large codebases than traditional tools like grep, find, and sed. |
Console Usage: Modern CLI Tools
Overview
This skill covers modern, faster alternatives to traditional command-line tools. These tools are designed for speed, usability, and safety when working with files at scale.
When to use this skill:
- Searching files and patterns (use
rg instead of grep)
- Finding files efficiently (use
fd instead of find)
- Replacing text in files (use
sd instead of sed)
- Syntax-aware code refactoring (use
ast-grep for multi-file changes)
- Bulk operations on multiple files (use
parallel for concurrent execution)
Tool Reference
rg - Ripgrep (Fast Pattern Searching)
Use instead of: grep, grep -r
Why: 50-100x faster than grep, respects .gitignore by default, better output formatting, colored matches
Basic usage:
rg "pattern"
rg "pattern" --type rust
rg "pattern" -C 3
rg "pattern" -l
rg "pattern" -n
rg -i "pattern"
rg "fn\s+\w+\(" --type rust
Key advantages:
- Respects .gitignore, .hgignore automatically
- Colored output by default
- Much faster on large codebases
- Supports regex out of the box
- Can filter by file type
Example:
rg "fn\s+(\w+)" --type rust -o
rg "console\.log" --type typescript
fd - File Discovery
Use instead of: find
Why: Simpler syntax, respects .gitignore by default, colored output, faster on modern filesystems
Basic usage:
fd "pattern"
fd -e rs
fd -e "ts" -e "js"
fd -t d "name"
fd -t f "name"
fd "pattern" --exclude node_modules
fd "pattern" /path/to/search
Key advantages:
- Respects .gitignore by default (use
--no-ignore to override)
- Simpler syntax than
find
- Colored output
- Faster on modern systems
- Intuitive type filtering
Example:
fd "\.test\.(ts|js)$"
fd -c newer "2024-03-01"
fd -e py --exclude __pycache__
sd - Safer Find-and-Replace
Use instead of: sed, sed -i
Why: Simpler syntax, preserves file permissions, atomic writes (no corruption), preview before replacing
Basic usage:
sd "old" "new" file.txt
sd -p "old" "new" file.txt
sd "old" "new" *.rs
sd '(\w+)\s+(\w+)' '$2 $1' file.txt
sd "old" "new" --case-preserve
sd "const " "let " file.js
Key advantages:
- Safer than sed - atomic writes prevent corruption
- Simpler syntax - no need to escape delimiters
- Preview mode to check changes before applying
- Preserves file permissions
- Can use regex capture groups
Comparison with sed:
sed -i 's/old/new/g' file.txt
sd "old" "new" file.txt
ast-grep - AST-Based Code Refactoring
Use instead of: regex-based find-and-replace for code
Why: Syntax-aware, matches actual code structure not just text patterns, handles nested structures, multi-file refactoring
Basic usage:
sg "pattern" --lang rust
sg "fn \$FUNC\(\) {}" --lang rust
sg "const \$name = \$value" --lang typescript -p
sg --lang rust "old_fn\(\)" -r "new_fn()" --rewrite
Key advantages:
- Understands code syntax, not just text
- Handles nested structures correctly
- Can match code patterns precisely
- Multi-file refactoring with
--rewrite
- Supports many languages: JavaScript, TypeScript, Python, Rust, Go, Java, C/C++, etc.
Use cases:
- Rename functions across a codebase
- Update API calls across projects
- Refactor imports
- Update deprecated patterns
- Replace method calls with new patterns
Example:
sg "console\.log\(\$_\)" --lang typescript -r "logger.debug($_)" --rewrite
sg "//\s*TODO" --lang rust -p
sg "import \$MODULE from '\$PATH'" --lang typescript -r "import type \$MODULE from '\$PATH'" --rewrite
parallel - Concurrent Operations
Use instead of: Running commands in a loop
Why: Execute operations on multiple files concurrently, dramatically faster for I/O-bound tasks
Basic usage:
find . -name "*.js" | parallel node check {}
fd -e rs | parallel cargo check
parallel --jobs 4 "command {}" ::: file1 file2 file3
parallel "echo {}" ::: a b c
Key advantages:
- Runs multiple operations in parallel
- Dramatically faster for batch operations
- Works with pipes and find output
- Can specify number of parallel jobs
- Handles quoting and escaping automatically
Example - Bulk transformation:
fd -e py | parallel black {}
fd -e rs | parallel cargo check {}
parallel "sed -i 's/old/new/g' {}" ::: *.txt
Workflow Patterns
Pattern 1: Find and Count
rg "pattern" -c | wc -l
rg "pattern" -l | wc -l
Pattern 2: Search then Replace
rg "old_pattern" -n
sd "old_pattern" "new_pattern" file.txt
sg "old_fn\(\)" --lang rust -p
sg "old_fn\(\)" --lang rust -r "new_fn()" --rewrite
Pattern 3: Bulk File Operations
fd -e rs --size +100k
fd -e rs | parallel cargo check {}
fd -e rs | parallel "sd 'old' 'new' {}"
Pattern 4: Large Refactoring
sg "old_function\(\$_\)" --lang typescript -p
sg "old_function\(\$_\)" --lang typescript -r "new_function($_)" --rewrite
git diff
Common Pitfalls to Avoid
❌ Don't use grep for large codebases
- Slow and inefficient
- ✅ Use
rg instead
❌ Don't use find with complex filters
- Verbose and hard to read syntax
- ✅ Use
fd instead
❌ Don't use sed for replacing in multiple files without backup
- Risk of corruption
- ✅ Use
sd instead, or commit to git first
❌ Don't use regex to refactor code
- Fragile, breaks on nested structures, doesn't understand syntax
- ✅ Use
ast-grep instead for code changes
❌ Don't process many files sequentially
- Slow for I/O-bound operations
- ✅ Use
parallel for concurrent execution
Installation & Availability
These tools are modern CLI utilities. Installation:
brew install ripgrep fd-find sd ast-grep parallel
sudo apt install ripgrep fd-find sd ast-grep parallel
Quick Reference
| Task | Traditional | Modern |
|---|
| Search files | grep -r | rg |
| Find files | find . -name | fd |
| Replace in file | sed -i | sd |
| Code refactoring | regex + sed | ast-grep |
| Bulk operations | for loop | parallel |
Why These Tools Matter
- Performance: 10-100x faster on real codebases
- Safety: Atomic writes, backups, previews
- Usability: Simpler syntax, sensible defaults
- Correctness: AST-aware refactoring handles edge cases
- Concurrency: Parallel execution for large workloads
Use these tools by default when working with files. They respect gitignore, provide better output, and work more safely than their traditional counterparts.