Brename
A practical cross-platform command-line tool for safely batch renaming files/directories via regular expression
Install / Use
/learn @shenwei356/BrenameREADME
brename: batch renaming safely
brename is a cross-platform command-line tool for safely batch renaming files/directories via regular expression.
Table of Contents
<!-- START doctoc generated TOC please keep comment here to allow auto update --> <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --> <!-- END doctoc generated TOC please keep comment here to allow auto update -->Features
-
Cross-platform. Supporting Windows, Mac OS X and Linux,
- Windows file systems, including NTFS and FAT, are case-insensitive.
Some operations are allowed on Linux, while they could be dangerous on Windows.
For example, renaming
test.tar.gztotest.tarwill overwriteTEST.tar.brename(v2.13.0 and later versions) can handle these cases appropriately (-wand-W).
- Windows file systems, including NTFS and FAT, are case-insensitive.
Some operations are allowed on Linux, while they could be dangerous on Windows.
For example, renaming
-
Safe. It helps you check potential conflicts and errors before it's too late.
<img src="screenshot/check-error.png" width="700"/>Some common conflict and errors that might happen with commands like
mvorrename.New path existed: Existed files might be overwritten, causing data loss.Overwriting newly renamed path. Existed files might be overwritten, causing data loss. This case is hard to check by eyes.Missing target: New file is empty, that's not allowed.New path ending with a space: Not allowed in Windows. It's legal in Linux, but might cause unexpected errors.New path ending with a period: Not allowed in Windows.
-
Supporting dry run. A good habbit.
<img src="screenshot/dry-run.png" width="700"/> -
Supporting Undo the LAST successful operation, like a time machine.
<img src="screenshot/undo.png" width="700"/> -
Overwrite can be detected and users can choose whether overwrite or leave it (
-o/--overwrite-mode). -
File filtering.
- Supporting including (
-f/--include-filters) and excluding (-F/--exclude-filters) files via regular expression. - No need to run commands like
find ./ -name "*.html" -exec CMD.
- Supporting including (
-
Renaming submatch with corresponding value via key-value file (
-r "{kv}" -k kv.tsv). -
Renaming via ascending integer (
-r "{nr}"). -
Automatically making directoy: e.g., renaming
a-b-c.txttoa/b/c.txt. -
Recursively renaming both files and directories (
-R/--recursive,-D/--including-dir,--only-dir).
Installation
brename is implemented in Go programming language,
executable binary files for most popular operating systems are freely available
in release page.
Method 0: Conda
Install conda, then run
conda install -c conda-forge brename
Or use mamba, which is faster.
mamba install -c conda-forge brename
Method 1: Download binaries
Tip: run brename -V to check update !!!
OS |Arch |File, 中国镜像 |Download Count
:------|:---------|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Linux |32-bit |brename_linux_386.tar.gz,<br/> 中国镜像 |
Linux |64-bit|brename_linux_amd64.tar.gz,<br/> 中国镜像 |
Linux |arm64 |brename_linux_arm64.tar.gz,<br/> 中国镜像 |
OS X |64-bit|brename_darwin_amd64.tar.gz,<br/> 中国镜像 |
OS X |arm64 |brename_darwin_arm64.tar.gz,<br/> 中国镜像 |
Windows|32-bit |brename_windows_386.exe.tar.gz,<br/> 中国镜像 |
Windows|64-bit|brename_windows_amd64.exe.tar.gz,<br/> 中国镜像|
Just download compressed
executable file of your operating system,
and decompress it with tar -zxvf *.tar.gz command or other tools.
And then:
-
For Linux-like systems
-
If you have root privilege simply copy it to
/usr/local/bin:sudo cp brename /usr/local/bin/ -
Or copy to anywhere in the environment variable
PATH:mkdir -p $HOME/bin/; cp brename $HOME/bin/
-
-
For windows, just copy
brename.exetoC:\WINDOWS\system32.
Method 2: Homebrew
brew install brename
Method 3: For ArchLinux AUR users
yaourt -S brename
Method 4: For Scoop users
scoop install brename
Method 5: Compiling from source
# download Go from https://go.dev/dl
wget https://go.dev/dl/go1.24.2.linux-amd64.tar.gz
tar -zxf go1.24.2.linux-amd64.tar.gz -C $HOME/
# or
# echo "export PATH=$PATH:$HOME/go/bin" >> ~/.bashrc
# source ~/.bashrc
export PATH=$PATH:$HOME/go/bin
git clone https://github.com/shenwei356/brename
cd brename
go build
# or statically-linked binary
CGO_ENABLED=0 go build -tags netgo -ldflags '-w -s'
# or cross compile for other operating systems and architectures
CGO_ENABLED=0 GOOS=openbsd GOARCH=amd64 go build -tags netgo -ldflags '-w -s'
Usage
brename: a practical cross-platform command-line tool for safely batch renaming files/directories via regular expression
Version: 2.14.0
Author: Wei Shen <shenwei356@gmail.com>
Homepage: https://github.com/shenwei356/brename
Warnings:
1. The path in file systems like FAT32 or NTFS is case-insens
