Bulk rename utility
Renames files/directories in bulk. Naming scheme (Name String) can be applied or regex replace can be performed to modify file names on the fly. It uses PCRE2 (revised version of PCRE) regex to provide search (and replace) functionality.
It provides versatile options to modify names, delete/replace part of it, indexing, case conversion, insert text, insert various file information like modification time, access time, permission etc.., insert parent directory names, working directory name etc.. and many more.
File search functionality is provided with PCRE2 regex. Fixed string search is also possible.
Operations (rename, changing names, search) are selective of file type (directory, file, link).
Files can be sorted by name, modification time, access time, size, file type (directory, file, link) etc..
It provides an undo functionality to move back unwanted rename operations. Different rnm operation on different directory remembers their own undo history.
Simulations can be run instead of actual rename to view the potential outcome as program output on terminal with the -sim option.
%d-%m-%Y), permission, owner id, group id, size, block, inode number, mode etc...
You can install it in Ubuntu from neurobin PPA (
sudo add-apt-repository -y ppa:neurobin/ppa sudo apt-get update sudo apt-get install rnm
If you are in precise (12.04), you will need to add ubuntu-toolchain repository to make
libstdc++6 (>=4.8.4) available:
sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test sudo add-apt-repository -y ppa:neurobin/ppa sudo apt-get update sudo apt-get install rnm
Install from AUR:
git clone https://aur.archlinux.org/rnm.git cd rnm makepkg -i
brew install neurobin/pkg/rnm
You can download a pre-built binary (64 bit, 32 bit, ppc64el) from the release page if available. These pre-built binaries depend on
libstdc++6 >= 4.8.4 if not specified otherwise.
Make sure you have a C++ compiler equivalent to GCC-4.8 (
g++-4.8) or later installed on your system.
It depends on three different libraries:
To install dependencies run the
cd rnm # i.e go inside the rnm project directory #Creating the following directories will prevent prepare.sh from installing the corresponding libraries. #mkdir -p gmpxx # uncomment and run this command if libgmp-dev (gmpxx) is already installed. #mkdir -p pcre2 # uncomment and run this command if libpcre2-dev (pcre2) is already installed. #mkdir -p jpcre2 # uncomment and run this command if libjpcre2-dev (jpcre2) is already installed. sh prepare.sh
After you have all the dependencies at hand, you can simply do:
autoreconf -f -i #run this one if your automake version is less than 1.15 ./configure --prefix=/usr make sudo make install
brew uninstall rnm
./configure --prefix=/usr && make && sudo make uninstall
-ns: Name string, simply new name for files. String wrapped with
/are treated as special rules and expanded to their special meaning.
-rs: Replace string. Performs regex replace to construct new name.
-ss: Searches files with matching regex.
-ssf: Searches files with matching fixed string.
-s: Sort files.
-fo: File only mode.
-do: Directory only mode.
-lo: Link only mode.
-dp: Depth of directories (how many subdirs to recurse).
-u: Undo the last rename operation in the current directory.
-up: Undo rename from an arbitrary undo path.
-ups: Show available undo paths.
-duh: Delete undo history older than the given seconds.
-duhd: Delete undo history older than the given days.
For a complete list of options and to get a glimpse of what rnm is capable of, get a peek at the doc (
rnm.md or rnm.html) or man page (
rnm -ns newname oldfile #rename by adding something to oldname: rnm -ns '/fn/ some text to add' oldfile
/fn/is a name string rule that expands to file name.
Rename all by appending index to file names:
rnm -ns '/n/ /i/./e/' ./* -dp -1
/n/is a name string rule which expands to file name without extension of the current renaming file.
/e/is a name string rule which expands to file extension.
/i/is another name string rule which expands to index.
-dp -1means unlimited depth i.e go to all subdirs.
Rename all by appending directory wise index to file names:
rnm -ns '/n/ /id/./e/' ./* -dp -1
/id/is a name string rule which expands to directory index (index inside directory).
Index with leading zeros ( file 001, 002 etc..):
rnm -ns '/n/ /id/./e/' -ifl 4 ./*
-ifl 4sets index field length to 4 and thus remaining space is filled with 0 (by default).
Use custom increment value:
rnm -ns '/n/ /id/./e/' -ifl 2 -inc 4 ./*
-inc 4sets the index increment value to 4.
rnm -ns '/n/ /-id/./e/' -ifl 3 -inc 4 ./*
-incis always positive, but decremented index can be accessed by appending
-in (at beginning) them.
Set starting index:
rnm -ns '/n/ /id/./e/' -ifl 3 -inc 4 -si 4 ./*
There are lots of magics you can do with index, like converting to binary, octal, hexadecimal etc.., converting to scientific or latin number, use index flags to manipulate their format etc.. Refer to the doc (rnm.md or rnm.html) or man page (
man rnm) for complete details.
rnm uses PCRE2 regex to provide regex replace on old filename. The general format for regex replace:
regex is the regex to match in the file name, replace is the string to replace the match with and modifiers are : g (global) i (case insensitive), d (directory), f (file), l (link).
rnm -rs '/(.*)_(.*)\.mp3/\2_\1.mp3/' ./*
-rstakes a replace string of the form
\1is captured group one,
\2is captured group 2.
Replace all _ (underscore) to space:
rnm -rs '/_/ /g' ./*
|test_file_123.mp3||test file 123.mp3|
|test_song_456.mp3||test song 456.mp3|
Change all .mp3 to .MP3 (uppercase):
rnm -rs '/\.mp3/\C/g' ./*
\C(capital C) in replace part converts the matched part to uppercase
Change all before
_ to (lowercase) and all after
. to (uppercase):
rnm -rs '/.*_/\c/;/.*\./\C/g' ./*
\c(small c) in replace part converts to lowercase.
Insert .link at the end for files that are symbolic link:
rnm -rs '/$/.link/l' ./*
the l modifier tells it to perform the replacement only to symbolic links, other modifiers f and d are available for files and directories respectively.
rnm comes with the power of PCRE2 regex and thus you can perform almost all kinds of file name modifications using regex replace. Name string rules (
/i/etc..) are applicable inside regex or replace part. If you have lots of regex replace to perform, you can put them into a file and give the file path with
-rs/foption. This option can be given multiple times to add multiple files.
-rsoption can also be given multiple times to add multiple replace string. Also replace string can be terminated with
;to add another replace string after it.
See the doc (rnm.md or rnm.html) or man page for complete details regarding regex replace.
Rename .mp3 files to .dummy:
rnm -ns '/fn/.dummy' -ss '\.mp3$' ./*
Rename all symbolic links to .link:
rnm -ns '/fn/.link' -ss '//l'
//land empty search string matches anything in file name. the l modifier tells it to match link, other modifiers f and d are available for files and directories respectively.
Rename .mp3 files to .dummy:
rnm -ns '/fn/.dummy' -ssf '.mp3' ./*
In this case .mp3 can match at the middle or start too.
Rename all files except .mp3 to .dummy:
rnm -ns '/fn/.dummy' -ss '/\.mp3$/!' ./* #or with fixed string: rnm -ns '/fn/.dummy' -ssf '/.mp3/!' ./* #for fixed string search, .mp3 will match at any place in the name
If you have lots of search strings, you can put them into files and add those files with
-ss/foption. This option can be given multiple time to add multiple files.
-ssoption can also be given multiple times to add multiple search string. See the docs (rnm.md or rnm.html) or man page for more ways and details.
There are several sorting mechanisms available:
-s: default sort (natural sort)
-s/g: general sort
-s/n: natural sort
-s/mt: sort according to file modification time (recent first)
-s/at: sort according to file access time (recent first)
-s/ct: sort according to file status change time (recent first)
-s/sz: sort according to file size (larger first)
-s/d: prioritize directory when sorting
-s/f: prioritize file when sorting
-s/l: prioritize link when sorting
-s/r: reverse the order sorted by above methods.
The default sort which comes with the option
-s is natural sort (
rnm -ns '/fn/ /id/' -s ./*
Add file modification time to file name:
rnm -ns '/fn/ @ /info-mtime-%d-%m-%Y %H:%I %p/' ./*
|file1||file1 @ 27-01-2017 12:35 AM|
|file2||file2 @ 17-01-2017 10:34 PM|
/info-prop-op/is another name string rule,
propis the property name (mtime, atime, perm, uid etc..) and
opis the format (optional).
Add file permission to file name:
rnm -ns '/fn/ /info-perm-ls/' ./*
permis another property for info name string rule,
op=lsis for permission resembling to
octis for octal permission.
There are lots of properties available for file info which makes all kinds of file information available. See the docs (rnm.md or rnm.html) or man page for details.
rnm -ns '/pd0/-/fn/' dir1/*.png
/pd0/is the immediate parent directory
rnm -ns '/pd1-0--/-/fn/' dir1/dir0/*.png
/pd1-0--/adds the directory names from
/pd0/with a delimiter in-between.
/pd0-1- /would become
dir0 dir1(here space is the delimiter). The general format is:
rnm -ns '/fn/ /ir/' -s/mt ./*
The above will append index to the filenames by sorting the files according to modification time (recent first).
/ir/is reserved-index (index is reserved for skipped files),
-s/mtsorts according to mtime.
rnm -ns '/fn/ /ir/' -s/sz ./*
The above will append index to the filenames by sorting the files according to size (larger first).
rnm -rs '/_/-/gf' -rs '/\./-/gd' -rs '/$/.link/l' ./*
This is what the above command does:
rnm -ns '/fn/ /info-mtime-%d-%m-%Y %H:%I %p/' -ss '/pattern1/f' -ss '/pattern2/d' -ss '/pattern3/l' ./*
If you are a developer, you can consider contributing to this project by forking this repository and making changes for better and do a pull request, or sharing ideas and suggestions or finding bugs, anything at all, what you think will be beneficial for this project.
If you aren't a developer, but still want to contribute, then you can support the contributing developers spiritually, by starring the repository and/or sharing ideas. If you want to be notified of the continuous development, you can add this in your watch list in Github.
If you see any problems or bugs please open an issue here
Copyright © 2016, Neurobin, All rights reserved.