brename -- a cross-platform command-line tool for safely batch renaming files/directories via regular expression
brename
is a cross-platform command-line tool for safely batch renaming files/directories via regular expression.
- Cross-platform. Supporting Windows, Mac OS X and Linux.
- Safe. By checking potential conflicts and errors.
- File filtering. Including and excluding files via regular expression.
No need to run commands like
find ./ -name "*.html" -exec CMD
. - Recursively renaming both files and directories.
- Supporting dry run.
brename
is implemented in Go programming language,
executable binary files for most popular operating systems are freely available
in release page.
OS | Arch | File, (mirror为中国用户下载镜像链接) | Download Count |
---|---|---|---|
Linux | 32-bit | brename_linux_386.tar.gz, (mirror) | |
Linux | 64-bit | brename_linux_amd64.tar.gz, (mirror) | |
OS X | 32-bit | brename_darwin_386.tar.gz, (mirror) | |
OS X | 64-bit | brename_darwin_amd64.tar.gz, (mirror) | |
Windows | 32-bit | brename_windows_386.exe.tar.gz, (mirror) | |
Windows | 64-bit | brename_windows_amd64.exe.tar.gz, (mirror) |
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 add the current directory of the executable file to environment variable
PATH
:echo export PATH=\$PATH:\"$(pwd)\" >> ~/.bashrc source ~/.bashrc
-
-
For windows, just copy
brename.exe
toC:\WINDOWS\system32
.
go get -u github.com/shenwei356/brename/
brename -- a cross-platform command-line tool for safely batch renaming files/directories via regular expression
Version: 2.1
Author: Wei Shen <[email protected]>
Homepage: https://github.com/shenwei356/brename
Attention:
1. Paths starting with "." is ignored.
2. Overwriting existed files is not allowed.
3. Flag -f/--include-filters and -F/--exclude-filters support multiple values,
e.g., -f ".html" -f ".htm".
But ATTENTION: comma in filter is treated as separater of multiple filters.
Usage:
brename [flags]
Examples:
1. dry run and showing potential dangerous operations
brename -p "abc" -d
2. dry run and only show operations that will cause error
brename -p "abc" -d -v 2
3. only renaming specific paths via include filters
brename -p ":" -r "-" -f ".htm$" -f ".html$"
4. renaming all .jpeg files to .jpg in all subdirectories
brename -p "\.jpeg" -r ".jpg" -R dir
5. using capture variables, e.g., $1, $2 ...
brename -p "(a)" -r "\$1\$1"
or brename -p "(a)" -r '$1$1' in Linux/Mac OS X
6. renaming directory too
brename -p ":" -r "-" -R -D pdf-dirs
More examples: https://github.com/shenwei356/brename
Flags:
-d, --dry-run print rename operations but do not run
-F, --exclude-filters stringSlice exclude file filter(s) (regular expression, case ignored). multiple values supported, e.g., -F ".html" -F ".htm", but ATTENTION: comma in filter is treated as separater of multiple filters
-i, --ignore-case ignore case
-f, --include-filters stringSlice include file filter(s) (regular expression, case ignored). multiple values supported, e.g., -f ".html" -f ".htm", but ATTENTION: comma in filter is treated as separater of multiple filters (default [.])
-D, --including-dir rename directories
-p, --pattern string search pattern (regular expression)
-R, --recursive rename recursively
-r, --replacement string replacement. capture variables supported. e.g. $1 represents the first submatch. ATTENTION: for *nix OS, use SINGLE quote NOT double quotes or use the \ escape character.
-v, --verbose int verbose level (0 for all, 1 for warning and error, 2 for only error)
-V, --version print version information and check for update
Take a directory for example:
$ tree
.
├── abc
│ ├── A.JPEG
│ ├── B.HTM
│ └── B.JPEG
├── a.jpeg
├── b.html
└── b.jpeg
-
Recursively renaming all
.jpeg
files to.jpg
in all subdirectories (-R/--recursive
). A dry run is firstly performed for safety checking (-d/--dry-run
).$ brename -p "\.jpeg" -r ".jpg" -R -d [INFO] checking: a.jpeg -> a.jpg [ok] [INFO] checking: b.jpeg -> b.jpg [ok] [INFO] 2 paths to be renamed $ brename -p "\.jpeg" -r ".jpg" -R [INFO] checking: a.jpeg -> a.jpg [ok] [INFO] checking: b.jpeg -> b.jpg [ok] [INFO] 2 paths to be renamed [INFO] renamed: a.jpeg -> a.jpg [INFO] renamed: b.jpeg -> b.jpg [INFO] 2 paths renamed $ tree . ├── abc │ ├── A.JPEG │ ├── B.HTM │ └── B.JPEG ├── a.jpg ├── b.html └── b.jpg
-
Dry run and only showing operations that will cause error (
-v/--verbose
)# default value of -v is 0 $ brename -p a -r b -R -d [INFO] checking: a.jpeg -> b.jpeg [new path existed] [INFO] checking: abc -> bbc [ok] [ERRO] 1 potential errors detected, please check $ brename -p a -r b -R -D -d -v 2 [INFO] checking: a.jpeg -> b.jpeg [new path existed] [ERRO] 1 potential errors detected, please check
-
Ignoring cases (
-i/--ignore-case
)$ brename -p "\.jpeg" -r ".jpg" -R -i [INFO] checking: abc/A.JPEG -> abc/A.jpg [ok] [INFO] checking: abc/B.JPEG -> abc/B.jpg [ok] [INFO] 2 paths to be renamed [INFO] renamed: abc/A.JPEG -> abc/A.jpg [INFO] renamed: abc/B.JPEG -> abc/B.jpg [INFO] 2 paths renamed $ tree . ├── abc │ ├── A.jpg │ ├── B.HTM │ └── B.jpg ├── a.jpg ├── b.html └── b.jpg
-
Using capture variables, e.g., $1, $2 ...
# or brename -p "(a)" -r '$1$1' in Linux/Mac OS X $ brename -p "(a)" -r "\$1\$1" -i [INFO] checking: a.jpg -> aa.jpg [ok] [INFO] 1 paths to be renamed [INFO] renamed: a.jpg -> aa.jpg [INFO] 1 paths renamed $ tree . ├── aa.jpg ├── abc │ ├── A.jpg │ ├── B.HTM │ └── B.jpg ├── b.html └── b.jpg
-
Renaming directory too (
-D/--including-dir
)$ brename -p "a" -r "A" -R -D [INFO] checking: aa.jpg -> AA.jpg [ok] [INFO] checking: abc -> Abc [ok] [INFO] 2 paths to be renamed [INFO] renamed: aa.jpg -> AA.jpg [INFO] renamed: abc -> Abc [INFO] 2 paths renamed $ tree . ├── AA.jpg ├── Abc │ ├── A.jpg │ ├── B.HTM │ └── B.jpg ├── b.html └── b.jpg
-
Only renaming specific files via include filters (regular expression) (
-f/--include-filters
)$ brename -p "^" -r "hello " -f ".htm$" -f ".html$" -R [INFO] checking: Abc/B.HTM -> Abc/hello B.HTM [ok] [INFO] checking: b.html -> hello b.html [ok] [INFO] 2 paths to be renamed [INFO] renamed: Abc/B.HTM -> Abc/hello B.HTM [INFO] renamed: b.html -> hello b.html [INFO] 2 paths renamed $ tree . ├── AA.jpg ├── Abc │ ├── A.jpg │ ├── B.jpg │ └── hello\ B.HTM ├── b.jpg └── hello\ b.html
-
Excluding files via exclude filters (regular expression) (
-F/--exclude-filters
)$ brename -p b -r c -d [INFO] checking: b.jpg -> c.jpg [ok] [INFO] checking: hello b.html -> hello c.html [ok] [INFO] 2 paths to be renamed $ brename -p b -r c -d -F '.html$' [INFO] checking: b.jpg -> c.jpg [ok] [INFO] 1 paths to be renamed
Create an issue to report bugs, propose new functions or ask for help.