Skip to content

mrvi0/batch-file-renamer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Batch File Renamer CLI

License: MIT Shell: Bash Platform: Linux Version: 1.0.0

πŸš€ Lightweight and fast CLI tool for batch file renaming with pattern support.

✨ Features

  • βœ… Prefix/Suffix Support - add prefixes or suffixes to filenames
  • πŸ”„ Extension Change - change file extensions easily
  • 🎯 Regex Patterns - use sed regex patterns for complex renaming
  • πŸ” Dry Run Mode - preview changes without actually renaming
  • πŸ“Š Verbose Output - detailed information about operations
  • πŸ›‘οΈ Safe Operations - checks for conflicts and permissions
  • ⚑ Fast Startup - single bash script, no dependencies
  • 🎨 Colored Output - beautiful terminal interface

πŸ› οΈ Installation

Installation Platform Dependencies

Quick Installation (Recommended)

# Clone the repository
git clone https://github.com/mrvi0/batch-file-renamer.git
cd batch-file-renamer

# Install to system
sudo ./install.sh

Manual Installation

# Make script executable
chmod +x batch-rename

# Copy to system directory
sudo cp batch-rename /usr/local/bin/

πŸš€ Usage

Usage Features Output

Basic Usage

# Add prefix to files
batch-rename --prefix "photo_" *.jpg

# Add suffix to files
batch-rename --suffix "_backup" *.txt

# Change file extension
batch-rename --ext "md" *.txt

# Use regex pattern
batch-rename --regex "s/document/doc/g" *.txt

Command Line Options

# Dry run (preview changes)
batch-rename --prefix "new_" --dry-run *.txt

# Verbose mode
batch-rename --prefix "test_" --verbose *.txt

# Combine operations
batch-rename --prefix "backup_" --suffix "_$(date +%Y%m%d)" *.log

# Full help
batch-rename --help

Usage Examples

1. Add Prefix to Files

batch-rename --prefix "photo_" *.jpg

Output:

πŸ”„ Starting batch rename operation...

βœ… Renamed: image1.jpg β†’ photo_image1.jpg
βœ… Renamed: image2.jpg β†’ photo_image2.jpg
βœ… Renamed: vacation.jpg β†’ photo_vacation.jpg

πŸ“Š Rename summary:
   Successfully renamed: 3 files

2. Add Suffix with Date

batch-rename --suffix "_$(date +%Y%m%d)" *.log

Output:

πŸ”„ Starting batch rename operation...

βœ… Renamed: app.log β†’ app_20241201.log
βœ… Renamed: error.log β†’ error_20241201.log

πŸ“Š Rename summary:
   Successfully renamed: 2 files

3. Change File Extension

batch-rename --ext "md" *.txt

Output:

πŸ”„ Starting batch rename operation...

βœ… Renamed: readme.txt β†’ readme.md
βœ… Renamed: changelog.txt β†’ changelog.md

πŸ“Š Rename summary:
   Successfully renamed: 2 files

4. Regex Pattern Replacement

batch-rename --regex "s/document/doc/g" *.txt

Output:

πŸ”„ Starting batch rename operation...

βœ… Renamed: document1.txt β†’ doc1.txt
βœ… Renamed: document2.txt β†’ doc2.txt

πŸ“Š Rename summary:
   Successfully renamed: 2 files

5. Dry Run Mode

batch-rename --prefix "test_" --dry-run *.txt

Output:

πŸ”„ Starting batch rename operation...
πŸ” DRY RUN MODE - No files will be actually renamed

πŸ“ Would rename: file1.txt β†’ test_file1.txt
πŸ“ Would rename: file2.txt β†’ test_file2.txt

πŸ“Š Dry run summary:
   Files that would be renamed: 2
   Errors: 0

6. Verbose Mode

batch-rename --prefix "final_" --verbose *.txt

Output:

πŸ”§ Operation Summary:
   Prefix: final_
   Files to process: 3

πŸ”„ Starting batch rename operation...

βœ… Renamed: draft.txt β†’ final_draft.txt
βœ… Renamed: notes.txt β†’ final_notes.txt
βœ… Renamed: temp.txt β†’ final_temp.txt

πŸ“Š Rename summary:
   Successfully renamed: 3 files

7. Complex Regex Pattern

batch-rename --regex "s/^([0-9]+)/file_\1/g" *.txt

Output:

πŸ”„ Starting batch rename operation...

βœ… Renamed: 001.txt β†’ file_001.txt
βœ… Renamed: 002.txt β†’ file_002.txt
βœ… Renamed: 100.txt β†’ file_100.txt

πŸ“Š Rename summary:
   Successfully renamed: 3 files

πŸ§ͺ Testing

Tests Coverage Status

Run tests to verify functionality:

chmod +x test.sh
./test.sh

Tests verify:

  • Help and version commands
  • Argument validation
  • Prefix operations
  • Suffix operations
  • Extension changes
  • Regex patterns
  • Dry run mode
  • Verbose mode
  • Error handling
  • File operations

πŸ“ Project Structure

batch-file-renamer/
β”œβ”€β”€ batch-rename         # Main bash script
β”œβ”€β”€ install.sh           # Installation script
β”œβ”€β”€ uninstall.sh         # Uninstall script
β”œβ”€β”€ test.sh              # Test suite
β”œβ”€β”€ examples/
β”‚   └── sample_files.txt # Example usage
β”œβ”€β”€ README.md           # Documentation
β”œβ”€β”€ README_RU.md        # Russian documentation
β”œβ”€β”€ LICENSE             # MIT license
└── .gitignore          # Ignored files

πŸ”§ Technical Details

Dependencies

  • bash 4.0+ - command line interpreter
  • sed - for regex operations (usually pre-installed)

Main Functions

  • generate_new_name() - create new filename based on rules
  • rename_files() - perform batch rename operations
  • validate_args() - validate command line arguments
  • check_file() - verify file existence and permissions

Supported Operations

  • Prefix: Add text before filename
  • Suffix: Add text before extension
  • Extension: Change file extension
  • Regex: Use sed patterns for complex replacements

Safety Features

  • Dry run mode for preview
  • Conflict detection (existing files)
  • Permission checking
  • File existence validation
  • Regex pattern validation

🎯 Use Cases

Photo Organization

# Add date prefix to photos
batch-rename --prefix "$(date +%Y%m%d)_" *.jpg

# Add location suffix
batch-rename --suffix "_paris" *.jpg

Document Management

# Convert text files to markdown
batch-rename --ext "md" *.txt

# Add version suffix
batch-rename --suffix "_v2.0" *.md

Backup Operations

# Create dated backups
batch-rename --prefix "backup_" --suffix "_$(date +%Y%m%d)" *.log

# Add timestamp
batch-rename --suffix "_$(date +%H%M%S)" *.conf

File Cleanup

# Remove unwanted prefixes
batch-rename --regex "s/^temp_//g" *.tmp

# Standardize naming
batch-rename --regex "s/^([0-9]+)/chapter_\1/g" *.txt

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • Inspired by the need for a simple, lightweight file renaming tool
  • Built with bash for maximum compatibility
  • Designed for Unix/Linux environments

About

Lightweight Bash CLI tool for batch renaming files with support for prefix, suffix, extension change, and regex patterns. No dependencies, fast and safe.

Topics

Resources

License

Stars

3 stars

Watchers

0 watching

Forks

Contributors

Languages