Linux tools to bulk rename files


The first tool to cover is called rnr and is written in Rust. It can be downloaded on GitHub where also some good examples can be found on how to use the tool.

Let’s try it out on a directory that we have with Markdown files. Due to a conversion, the file names include a date. As this is no longer needed, we want to strip out the date and only get the bit after the third hyphen.

  • Original file name:
  • Wanted file name:
# rnr --dry-run '\d+-\d+-\d+-' '' ./*.md
This is a DRY-RUN
./ -> ./
./ -> ./
./ -> ./
./ -> ./
--dry-runDon’t make changes right away, but show what will be done
'(\d+)-(\d+)-(\d+)-'Capture three occurrences of just numbers
''Replace with empty string, as we want to strip the date
./*.mdOnly apply this to the Markdown files in this current directory

The nice part of rnr is that it shows the rename it will do. As this looks good, we can tell it to perform the action. In that case replace the dry-run with --force to make the actual changes.

Rename tool

The rename tool with the similar name rename can be found on many Linux systems. It used a Perl syntax for the matching, so with some fiddling we can do the same bulk action as before.

If the tool is not installed yet, here are some pointers on the right package

Linux distributionPackage nameInstallation
Ubunturenameapt install rename


# rename --nono 's/\d{4}-\d{2}-\d{2}-//' ./*.md
rename(./, ./
rename(./, ./
rename(./, ./
--nonoDo not make actual changes
's/\d{4}-\d+{2}-\d{2}-//'Do a search (s), first 4 digits, hyphen, 2 digits, hyphen, 2 digits, hyphen. No replacement text, as we want to strip text from the file name


Another great utility can be found in the Python Package Index (PyPi) and is named regex-rename. As the name implies, it also support regular expressions.


pip3 install regex-rename

Tip: do the installation in a virtual environment (python3-virtualenv)


The next step is forming the regular expression. This utility does a “dry-run” by default and requires the --rename option to make actual changes.

# regex-rename "(\d{4})-(\d{2})-(\d{2})-(.*)" "\4"
[2024-03-28 14:03:51] DEBUG matching regular expression pattern to files: pattern=(\d{4})-(\d{2})-(\d{2})-(.*) replacement=\4 dry_run=True full_match=False recursive=False padding=None
[2024-03-28 14:03:51] INFO  matched file: group_1=2014 group_2=03 group_3=02
[2024-03-28 14:03:51] INFO  matched file: group_1=2014 group_2=03 group_3=06
[2024-03-28 14:03:51] INFO  matched file: group_1=2014 group_2=03 group_3=09
[2024-03-28 14:03:51] INFO  files matched the pattern: matched=3 mismatched=0

Let’s have a look at the regular expression first.

Regular expression partExplanation
"Open the regular expression
(\d{4})-Match 4 digits, followed by a hyphen
(\d{2})-(\d{2})-Match 2 digits, hyphen, 2 digits, hyphen
(.*)Match all characters, so that we can use this part as our replacement
"Close the regular expression

The output of the tool is colored and shows what it is trying to do. We see also the dry_run=True that tells us that it won’t make any changes. It shows what files match and what the new file name would be. Another great tool do do a batch rename action.

Got another tool that you really like to use for batch renaming? Let us know!

Relevant commands in this article

Like to learn more about the commands that were used in this article? Have a look, for some there is also a cheat sheet available.

  • regex-rename
  • rename
  • rnr


Small picture of Michael Boelen

This article has been written by our Linux security expert Michael Boelen. With focus on creating high-quality articles and relevant examples, he wants to improve the field of Linux security. No more web full of copy-pasted blog posts.

Discovered outdated information or have a question? Share your thoughts. Thanks for your contribution!

Mastodon icon