🐮 COWcase.sh & JUSTcase.sh

Batch File/Directory Case Conversion

Back to Home View Source Code Full Documentation

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

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:

  1. Extracts the first character of the filename using Bash parameter expansion
  2. Converts it to uppercase (${var^}) or lowercase (${var,})
  3. Reconstructs the name with the converted character
  4. Renames only if the new name differs from the original
  5. In recursive mode, processes directories deepest-first to avoid path conflicts
  6. Logs each operation for auditing (COWcase.sh only)

Dependencies

COWcase.sh works without cowsay/lolcat but will gracefully skip visual messages if they're unavailable. JUSTcase.sh has zero external dependencies.

Troubleshooting

Safety Notes

Use Cases