Overview
COWcase.sh and JUSTcase.sh standardize file and directory naming by batch converting the first character case. COWcase provides rich visual feedback and logging; JUSTcase is a lean alternative for speed and scripting integration.
Key Features
- Case Conversion Modes: Lowercase by default; uppercase with −u flag
- Selective Processing: Process directories only (−d), files only (−f), or both
- Custom Path Targeting: Specify target directory with −p flag (defaults to current directory)
- Safe Renaming: Only renames items when new name differs from original
- Visual Feedback: Cowsay/lolcat messages when available (graceful fallback)
- Comprehensive Logging: Detailed output of all rename operations
- Error Handling: Robust recovery with clear error messages
Installation & Setup
# No dependencies required (optional cowsay/lolcat for COWcase.sh visual feedback)
cd BASHparaphernalia/scripts/COWcase
chmod +x COWcase.sh JUSTcase.sh
# View help
./COWcase.sh -h
Command-Line Options
COWcase.sh [OPTIONS]
OPTIONS:
-u Convert to UPPERCASE (default: lowercase)
-d Process directories only
-f Process files only
-r Enable recursive processing (all subdirectories)
-n Dry-run mode (preview without applying)
-p PATH Specify target directory (default: current directory)
EXAMPLES:
./COWcase.sh # Lowercase directories in current
./COWcase.sh -f # Lowercase files only
./COWcase.sh -f -u # Uppercase files only
./COWcase.sh -r # Recursive: lowercase all dirs
./COWcase.sh -f -r -n # Preview recursive file rename (dry-run)
./COWcase.sh -d -u -p ~/Documents # Uppercase dirs in ~/Documents
Practical Examples
Standardize Directory Names to Lowercase
# Convert all directories in current folder to lowercase
./COWcase.sh -d
# Before: MyPhotos, OldBackups, WebContent
# After: myPhotos, oldBackups, webContent
Uppercase All Files Recursively (Preview First)
# Dry-run preview of recursive file rename
./COWcase.sh -f -u -r -n
# Then apply the changes:
./COWcase.sh -f -u -r
Mixed Processing in Nested Directories
# Convert all files and directories recursively to lowercase
./COWcase.sh -r -p ~/my_project
# Before: README.md, SrcCode/, HelpDocs/, config.json
# After: rEADME.md, srcCode, helpDocs, config.json
Note: Only the first character is converted; the rest remains unchanged.
How It Works
COWcase.sh iterates through files/directories in the specified path and:
- Extracts the first character of the filename using Bash parameter expansion
-
Converts it to uppercase (
${var^}) or lowercase (${var,}) - Reconstructs the name with the converted character
- Renames only if the new name differs from the original
- In recursive mode, processes directories deepest-first to avoid path conflicts
- Logs each operation for auditing (COWcase.sh only)
Dependencies
- Required: Bash 4.0+,
mvcommand - Optional (COWcase.sh): cowsay, lolcat (for visual feedback)
- Optional (JUSTcase.sh): None
COWcase.sh works without cowsay/lolcat but will gracefully skip visual messages if they're unavailable. JUSTcase.sh has zero external dependencies.
Troubleshooting
-
Permission denied: Make scripts executable with
chmod +x COWcase.sh JUSTcase.sh - Command not found: Use full path to script or ensure it's in your PATH
- No renaming occurs: Check target directory exists; verify files match mode (-f or -d)
- Rename fails: Check file permissions; ensure you have write access to the directory
- Special characters in names: Scripts handle most special characters safely
- Recursive mode slow: JUSTcase.sh is faster for large trees (no logging overhead)
- Very long filenames: Script works with standard Unix filename limits
Safety Notes
- Non-destructive: Only changes the first character; preserves file extensions and rest of name
- Skip identical names: Won't rename if new name would be identical to original
- Error reporting: Clear messages for failures; continues on individual errors
- Logging: All operations logged for auditing and recovery
Use Cases
- Project standardization: Enforce consistent naming conventions across teams
- Bulk cleanup: Quickly normalize naming in large directories
- Automation: Include in deployment scripts to standardize file structures
- Media organization: Standardize photo/video folder names
- Documentation: Enforce consistent documentation directory naming