A comprehensive bash script to normalize file names with multiple case style options, smart defaults, and extensive commenting for future developers.
- 8 Case Styles Available: snake_case, kebab-case, camelCase, PascalCase, UPPER_SNAKE, flatcase, UPPERCASE, slug-case
- Smart Defaults: Press ENTER to accept sensible defaults for quick operation
- Intelligent Renaming: Only renames files that need it - properly named files are left unchanged
- Always Lowercase Extensions: File extensions are always normalized to lowercase regardless of case style
- Target Directory Control: Choose your output directory with default handling for existing directories
- Comprehensive Comments: Extensively documented code for future developers
- Recursive Processing: Handles files in subdirectories (flattened to output directory)
- Safe Operation: Copies files to a new directory, leaving originals untouched
- Git Integration: Output directory automatically ignored via .gitignore
No installation required. Simply ensure you have bash available (standard on Linux/macOS).
Tested on: Ubuntu 22.04
For fastest operation, simply run the script and press ENTER for all prompts to use defaults:
./normalize_filenames.shDefault settings:
- Source directory:
./files - Target directory:
./files-renamed - Case style:
snake_case - Existing directory handling: Delete and recreate
Follow the interactive prompts to customize:
- Source Directory: Where your files are located (default:
./files) - Target Directory: Where normalized files will be saved (default:
./files-renamed) - Existing Directory Handling:
- Option 1 (default): Delete existing target directory and start fresh
- Option 2: Preserve existing directory and add files to it
- Case Style Selection:
-
- snake_case (my_file_name.txt) - DEFAULT
-
- kebab-case (my-file-name.txt)
-
- slug-case (my-file-name.txt) - same as kebab
-
- camelCase (myFileName.txt)
-
- PascalCase (MyFileName.txt)
-
- UPPER_SNAKE (MY_FILE_NAME.txt)
-
- flatcase (myfilename.txt)
-
- UPPERCASE (MYFILENAME.txt)
-
My Document.txtPhoto 2024-05-30.jpgUPPERCASE FILE.DOCProject_Final-Version (2).pdfBudget Analysis FINAL.XLS
snake_case (default):
my_document.txtphoto_2024_05_30.jpguppercase_file.docproject_final_version_2.pdfbudget_analysis_final.xls
camelCase:
myDocument.txtphoto20240530.jpguppercaseFile.docprojectFinalVersion2.pdfbudgetAnalysisFinal.xls
PascalCase:
MyDocument.txtPhoto20240530.jpgUppercaseFile.docProjectFinalVersion2.pdfBudgetAnalysisFinal.xls
UPPER_SNAKE:
MY_DOCUMENT.txtPHOTO_2024_05_30.jpgUPPERCASE_FILE.docPROJECT_FINAL_VERSION_2.pdfBUDGET_ANALYSIS_FINAL.xls
The ./files directory contains sample files with various naming issues for testing purposes. Delete these sample files before adding your own files to rename.
To clear sample files:
rm -rf ./files/*- Always lowercase: Extensions are normalized to lowercase regardless of case style
- Examples:
.TXT→.txt,.PDF→.pdf,.JPG→.jpg
- Smart detection: Files already properly named are copied as-is
- Safe operation: Original files are never modified, only copied
- Recursive flattening: Subdirectory files are copied to the target directory root
Each case style has specific character and formatting requirements:
- snake_case / UPPER_SNAKE: Letters, numbers, underscores only
- kebab-case / slug-case: Letters, numbers, hyphens only
- camelCase: Starts lowercase, mixed case, no separators
- PascalCase: Starts uppercase, mixed case, no separators
- flatcase: All lowercase, no separators
- UPPERCASE: All uppercase, no separators
The script is extensively commented for future developers:
- Function documentation with parameters and return values
- Section headers explaining each part of the script
- Inline comments for complex operations
- Clear variable naming and logical flow
- Output directory (
files-renamed/) is automatically ignored via.gitignore - Comprehensive
.gitignoreincludes Node.js, OS-specific, and development tool files