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 fiddlng we can do the same bulk action as before.

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

Linxux 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!

Take the next step!

Want to learn more about Linux security? Have a look at the open source tool Lynis and become a Linux security expert yourself.

Lynis is a battle-tested technical security audit tool. It is open source, freely available, and used by system administrators all over the world. Other users include IT auditors, security professionals, like pentesters.

Tool Information

Visit project page
Screenshot of Lynis security tool