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.
Features at a glance:
- Rename files/directories/links en masse with dynamically constructed names.
- Undo rename.
- Names (or name strings) can be taken from a file.
- Inserting file information (mtime, atime, ctime, permission etc..) in arbitrary formats.
- Indexing and formatting the indexes in different ways.
- Latin, scientific and base conversion for indexes and counters.
- Inserting different level of parent directory names.
- Access to current directory name, file name with and without extension.
- Regex replace to delete/swap/replace part of the file name.
- A regex replace operation can be performed on file only, directory only, link only or any combination of them.
- Uppercase/Lowercase conversion on file name (can be done by selecting a part).
- Replace strings can be taken from files.
- Search string to search for files with matching regex/string.
- Search string can be specified for only file, directory, link or any combination of them.
- Inverse search.
- Search strings can be taken from files.
- Sorting files and indexing.
- Sorting files according to size, modification time, access time etc..
- Prioritize file, directory or link during sort.
- Running simulation.
- Unlimited precision for numbers i.e you can perform base conversion, scientific conversion etc.. on an arbitrarily big number. This functionality is provided by GMP BigNum library (GNU Multi-precession library).
- File information is available, e.g modification time, access time, status change time (time string can be formatted using format string e.g
%d-%m-%Y), permission, owner id, group id, size, block, inode number, mode etc...
- Inverse search is possible.
- Each regex operation can be associated with either link, file or directory, for example, if a replace string is associated with only file, it will not work on directories or links.
- New sorting methods:
- Sort according to file modification time (recent first).
- Sort according to file access time (recent first).
- Sort according to file status change time (recent first).
- Sort according to file size (larger first).
- Prioritize directory when sorting.
- Prioritize file when sorting.
- Prioritize link when sorting.
- Reverse sort (can be used to reverse the order of a previous sort).
For Ubuntu and derivatives:
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
Using Homebrew (MacOS) or Linuxbrew (Any Linux distro):
brew install neurobin/pkg/rnm
From pre-built binaries:
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
- For Debian, Ubuntu and derivatives, uninstall from software manager.
- For Archlinux, uninstall with pacman.
- For MacOS, uninstall with
brew uninstall rnm
- If you used a pre-built binary, just delete the binary and the man page.
- If you compiled from the source, do
./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.
Change/Modify/remove part of a file name
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.
Search for files and rename:
Search with regex:
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.
Search with fixed string:
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.
Sort and rename:
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 ./*
Insert file information
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.
Add/Insert parent directory names to filename:
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:
Index files by sorting them according to modification time:
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.
Index files by sorting them according to size:
rnm -ns '/fn/ /ir/' -s/sz ./*
The above will append index to the filenames by sorting the files according to size (larger first).
Treat files, directories, links differently in a single command to rename files:
rnm -rs '/_/-/gf' -rs '/\./-/gd' -rs '/$/.link/l' ./*
This is what the above command does:
- Replace all underscores with hyphen for regular files (
- Replace all dot with hyphen for directories (
- Give all symbolic links a .link extension (
Search for files matching pattern1 in their name, directories matching pattern2 and links matching pattern3 and append modification time with the filename:
rnm -ns '/fn/ /info-mtime-%d-%m-%Y %H:%I %p/' -ss '/pattern1/f' -ss '/pattern2/d' -ss '/pattern3/l' ./*