A command-line tool to batch rename files and directories
Last updated Jun 30, 2026
589
Stars
19
Forks
12
Issues
+1
Stars/day
Attention Score
61
Topics
Language breakdown
Rust 100.0%
βΈ Files
click to expand
README
RnR is a command-line tool to securely rename multiple files and directories that supports regular expressions.
Features
- Batch rename files and directories.
- Automated checks to avoid unwanted file collisions, removals or overwrites.
- Use regexp, including capture groups.
- Include directories recursively.
- Create backup files.
- Create and read operations from dump file.
- Undo operations from dump file.
- Exclude/include hidden files.
- Linux, Mac and Windows support, including terminal coloring.
- Extensive unit testing.
- Select limit of replacements.
- Apply text transformations to the replacements including capture groups.
- Convert UTF-8 file names to ASCII representation.
Install
Binaries
GitHub Releases
You can download binaries from latest release page, choose the compressed file corresponding to your platform. These compressed files contain the executable and other additional content such as completion files (Bash, Zsh, fish and PowerShell).Arch Linux
A package is available in the AUR (rnr) to install latest version of
RnR on Arch Linux.
Homebrew
You can use Homebrew package manager to install this tool in macOS or Linux systems.brew install rnr
From Source
RnR is written in Rust. You can build it from source using Cargo.From git repository
git clone https://github.com/ismaelgv/rnr .
cargo install
From Crates.io
cargo install rnr
Usage
Options
Check a detailed description of the application usage and all its options using:rnr help.
Default behavior
- Checks all operations to avoid overwriting existing files.
- Only UTF-8 valid input arguments and filenames.
- Works on files and symlinks (ignores directories).
- Accepts multiple files as arguments.
- Accepts a regex to generate matches. These expressions have same
regex crate. You can check regex syntax
here. It supports numbered and named *capture
groups*.
If max depth is not provided to recursive mode, it is assumed infinite*.
- Does not generate backups.
- Ignore hidden files and directories.
- Dump all operations into a file in force mode. This dump file can be used to
from-file subcommand.
- Number of replacements set to one.
Examples
* Include directories * Multiple replacements * Combination with other UNIX tools * Recursive rename with max directory depth * Recursive rename including directories and hidden files- Undo/redo operations using dump file
- Create backup files before renaming
- Convert UTF-8 file names to ASCII
- Advanced regex examples
NOTE: If the regular expression EXPRESSION contains - as initial character, the application with parse it as an argument. You need to use -- after flags and before the arguments, for example rnr regex -f -- '-foo' '-bar' [...].
WINDOWS NOTE: In the examples that use *, you need to expand the wildcard in PowerShell, for example: rnr regex a b (Get-Item ./*). This is not supported in cmd.exe.
Rename a list of files
You can pass a list of files to be renamed as arguments:rnr regex -f file renamed ./file-01.txt ./one/file-02.txt ./one/file-03.txt
Original tree
.
βββ file-01.txt
βββ file-02.txt
βββ file-03.txt
βββ one
βββ file-01.txt
βββ file-02.txt
βββ file-03.txt
Renamed tree
.
βββ renamed-01.txt
βββ file-02.txt
βββ file-03.txt
βββ one
βββ file-01.txt
βββ renamed-02.txt
βββ renamed-03.txt
Include directories
Directories are ignored by default but you can also include them to be renamed using the option-D.
rnr regex -f -D foo bar ./*
Original tree
.
βββ foo
β βββ foo.txt
βββ foo.txt
Renamed tree
.
βββ bar
β βββ foo.txt
βββ bar.txt
Multiple replacements
The replacement limit is set to 1 by default, but you can configure this limit to replace multiple non-overlapping matches. All matches will be replaced if this option is set to 0.rnr regex -f -l 0 o u ./*
Original tree
.
βββ foo.txt
βββ foofoo.txt
βββ foofoofoo.txt
βββ foofoofoofoo.txt
Renamed tree
.
βββ fuu.txt
βββ fuufuu.txt
βββ fuufuufuu.txt
βββ fuufuufuufuu.txt
Combination with other UNIX tools
You can combinernr with other UNIX tools using pipes to pass arguments.
Find files older than 1 day and rename them
find . -type f +mtime 1 | xargs rnr regex -f file renamed
Read list of files from a file
cat file_list.txt | xargs rnr regex -f file rename
file_list.txt content:
file-01.txt one/file-02.txt one/file-03.txt
Recursive rename
If recursive (-r) option is passed, rnr will look for al files in the path recursively without depth limit.
rnr regex -f -r file renamed ./
Original tree
.
βββ file-01.txt
βββ file-02.txt
βββ file-03.txt
βββ one
βββ file-01.txt
βββ file-02.txt
βββ file-03.txt
βββ two
βββ file-01.txt
βββ file-02.txt
βββ file-03.txt
βββ three
βββ file-01.txt
βββ file-02.txt
βββ file-03.txt
Renamed tree
.
βββ renamed-01.txt
βββ renamed-02.txt
βββ renamed-03.txt
βββ one
βββ renamed-01.txt
βββ renamed-02.txt
βββ renamed-03.txt
βββ two
βββ renamed-01.txt
βββ renamed-02.txt
βββ renamed-03.txt
βββ three
βββ renamed-01.txt
βββ renamed-02.txt
βββ renamed-03.txt
Recursive rename with max directory depth
Similarly, you can set a maximum directory depth in combination with recursive operations.rnr regex -f -r -d 2 file renamed ./
Original tree
.
βββ file-01.txt
βββ file-02.txt
βββ file-03.txt
βββ one
βββ file-01.txt
βββ file-02.txt
βββ file-03.txt
βββ two
βββ file-01.txt
βββ file-02.txt
βββ file-03.txt
βββ three
βββ file-01.txt
βββ file-02.txt
βββ file-03.txt
Renamed tree
.
βββ renamed-01.txt
βββ renamed-02.txt
βββ renamed-03.txt
βββ one
βββ renamed-01.txt
βββ renamed-02.txt
βββ renamed-03.txt
βββ two
βββ file-01.txt
βββ file-02.txt
βββ file-03.txt
βββ three
βββ file-01.txt
βββ file-02.txt
βββ file-03.txt
Recursive rename including directories and hidden files
rnr ignore hidden files by default to speed up the operations and avoid problems with some particular directories like .git/ or .local/. You can include hidden files passing -x option. Also, you can use include directories -D option with -r too.
rnr regex -f -r -D -x foo bar ./
Original tree
.
βββ .foohiddenfile.txt
βββ foo.txt
βββ foo
β βββ foo.txt
β βββ foo
β βββ foo.txt
βββ .foohiddendir
βββ foo.txt
Renamed tree
.
βββ .barhiddenfile.txt
βββ bar.txt
βββ bar
β βββ bar.txt
β βββ bar
β βββ bar.txt
βββ .barhiddendir
βββ bar.txt
Undo/redo operations using dump file
When you perform a renaming operation,rnr will create by default a dump file in the current directory you executed the command. This file can be used to easily revert the operations using from-file and -u option.
Rename operation
rnr regex -f foo bar ./* Undo previous operation rnr from-file -f -u rnr-[timestamp].json
If you want to redo the operation just pass the dump file without any additional argument:
rnr from-file -f rnr-[timestamp].json
Create backup files before renaming
rnr can create backup files before renaming for any operation passing -b option. The backup files names are ensured to be unique and won't be overwritten if another backup is created. If you are working with many large files, take into account that files will be duplicated.
rnr regex -f -b file renamed ./*
Original tree
. βββ file-01.txt βββ file-02.txt βββ file-03.txt Renamed tree . βββ file-01.txt.bk βββ file-02.txt.bk βββ file-03.txt.bk βββ renamed-01.txt βββ renamed-02.txt βββ renamed-03.txt
Convert UTF-8 file names to ASCII
rnrcan convert UTF-8 file names to their ASCII representation. This feature uses
AnyAscii library to perform the
transliteration. To avoid conflicts with paths, the characters that would be translated
to / are changed to _ instead.
You can run:
rnr to-ascii ./* Or: rnr to-ascii -r .
Original tree
. βββ fΓ―lΓ©-01.txt βββ FΓ―ΔΉΓ-02.txt βββ file-03.txt Renamed tree . βββ file-01.txt βββ FILE-02.txt βββ file-03.txt
Advanced regex examples
More info about regex used in theregex package.
Replace extensions
rnr regex -f '\..$' '.txt' ./
Original tree
.
βββ file-01.ext1
βββ file-02.ext2
βββ file-03.ext3
Renamed tree
.
βββ file-01.txt
βββ file-02.txt
βββ file-03.txt
Replace numbers
rnr regex -f '\d' '1' ./*
Original tree
.
βββ file-01.txt
βββ file-02.txt
βββ file-03.txt
Renamed tree
.
βββ file-11.txt
βββ file-12.txt
βββ file-13.txt
Capture groups
- Capture three unnamed groups [
name(1)-number(2).extension(3)]. - Swap group 1 (name) and group 2 (number).
rnr regex -f '(\w+)-(\d+).(\w+)' '${2}-${1}.${3}' ./*
Original tree
.
βββ file-01.txt
βββ file-02.txt
βββ file-03.txt
Renamed tree
.
βββ 01-file.txt
βββ 02-file.txt
βββ 03-file.txt
SHELL NOTE: In shells like Bash and zsh, make sure to wrap the REPLACEMENT
pattern in single quotes. Otherwise, capture group indices will be replaced by
expanded shell variables.
Capture several named groups and swap them
- Capture two digits as
number. - Capture extension as
ext. - Swap groups.
rnr regex -f '(?P<number>\d{2})\.(?P<ext>\w{3})' '${ext}.${number}' ./*
Original tree
.
βββ file-01.txt
βββ file-02.txt
βββ file-03.txt
Renamed tree
.
βββ file-txt.01
βββ file-txt.02
βββ file-txt.03
Capture several groups and apply a transformation
- Capture three unnamed groups [
name(1)-number(2).extension(3)]. - Swap group 1 (name) and group 2 (number).
- Transform replacement to uppercase.
rnr regex -f -t upper '(\w+)-(\d+)' '${2}-${1}' ./*
Original tree
.
βββ file-01.txt
βββ file-02.txt
βββ file-03.txt
Renamed tree
.
βββ 01-FILE.txt
βββ 02-FILE.txt
βββ 03-FILE.txtπ More in this category