"renumber" renames the filenames supplied according to the template provided as the first argument using a consecutive numbering scheme. By default, filenames are sorted before numbering.
- Python 3.6+
"renumber" is designed to make use of POSIX shell features.
Maybe you’ve received some files in a directory from someone else, maybe off the internet. And their naming scheme sucks, maybe hashes. So just rename all those files so they are consecutively numbered. Most "downloader" programs enable you to do this, but if you missed that step it can be a pain to manually renumber files. I recommend using in conjunction with rename(1p).
The Perl One-Liners Guide contains some ideas for using the rename command with incrementing numbers. In brief:
# Replace the first occurrence of digits in the filename with an
# incrementing sequence.
rename 's/\d+/++$a/e' *.png
# Likewise with a format string:
rename 's/\d+/sprintf "%03d", ++$a/e' *.png
The Thunar(1) File Manager for Xfce has a similar capability called "Bulk Rename" with a convenient graphical interface. You are however limited on where you can place the number in the new name. The only requirement of this program’s template string is that the number has to go somewhere.
renumber set_%3d.jpg *.jpg
This example will rename all files matching *.jpg to
set_001.jpg, set_002.jpg, set_003.jpg, etc.
Use the --help option to show info about further options.
Use the --man option to show info about formatting directives
for the template.
The default sorting method is caseless natural sort, sometimes called "version" sort or "sorting for humans." This method can be changed or sorting disabled altogether using the options.
Copyright © 2021, 2022, 2024–2026 Dylan Maltby
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/.