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.
- 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).
You can install it in Ubuntu from neurobin PPA (ppa: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
Install from neurobin/pkg/rnm
with brew
:
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 prepare.sh
file:
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 (man rnm
).
Simplest example:
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
Before | After |
---|---|
file.mp3 | file 1.mp3 |
song.mp3 | song 2.mp3 |
video/song.mp4 | video/song 3.mp4 |
/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 -1
means 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
Before | After |
---|---|
dir1/file.mp3 | dir1/file 1.mp3 |
dir1/song.mp3 | dir1/song 2.mp3 |
dir2/file.mp3 | dir2/file 1.mp3 |
dir2/song.mp3 | dir2/song 2.mp3 |
/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 ./*
Before | After |
---|---|
file.mp3 | file 0001.mp3 |
song.mp3 | song 0002.mp3 |
... | ... |
video.mp4 | video 0010.mp4 |
-ifl 4
sets 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 ./*
Before | After |
---|---|
file.mp3 | file 01.mp3 |
song.mp3 | song 05.mp3 |
-inc 4
sets the index increment value to 4.
Decreasing index:
rnm -ns '/n/ /-id/./e/' -ifl 3 -inc 4 ./*
Before | After |
---|---|
file.mp3 | file -001.mp3 |
song.mp3 | song -005.mp3 |
-inc
is 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 ./*
Before | After |
---|---|
file.mp3 | file 004.mp3 |
song.mp3 | song 008.mp3 |
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/replace/modifier'
where 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).
swap parts:
rnm -rs '/(.*)_(.*)\.mp3/\2_\1.mp3/' ./*
Before | After |
---|---|
test_file.mp3 | file_test.mp3 |
test_song.mp3 | song_test.mp3 |
-rs
takes a replace string of the form/regex/replace/modifier
\1
is captured group one,\2
is captured group 2.
Replace all _ (underscore) to space:
rnm -rs '/_/ /g' ./*
Before | After |
---|---|
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' ./*
Before | After |
---|---|
test_file_123.mp3 | test_file_123.MP3 |
test_song_456.mp3 | test_song_456.MP3 |
\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' ./*
Before | After |
---|---|
TEST_file_123.mp3 | test_file_123.MP3 |
TEST_song_456.mp3 | test_song_456.MP3 |
\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 (
/fn/
,/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/f
option. This option can be given multiple times to add multiple files.-rs
option 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$' ./*
Before | After |
---|---|
file1.mp3 | file1.mp3.dummy |
file2.mp3 | file2.mp3.dummy |
file3.mp4 | file3.mp4 |
Rename all symbolic links to .link:
rnm -ns '/fn/.link' -ss '//l'
//l
and 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' ./*
Before | After |
---|---|
file1.mp3 | file1.mp3.dummy |
file2.mp3 | file2.mp3.dummy |
file3.mp4 | file3.mp4 |
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
Before | After |
---|---|
file1.mp3 | file1.mp3 |
file2.mp3 | file2.mp3 |
file3.mp4 | file3.mp4.dummy |
If you have lots of search strings, you can put them into files and add those files with
-ss/f
option. This option can be given multiple time to add multiple files.-ss
option 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 (-s/n
).
rnm -ns '/fn/ /id/' -s ./*
Add file modification time to file name:
rnm -ns '/fn/ @ /info-mtime-%d-%m-%Y %H:%I %p/' ./*
Before | After |
---|---|
file1 | file1 @ 27-01-2017 12:35 AM |
file2 | file2 @ 17-01-2017 10:34 PM |
/info-prop-op/
is another name string rule,prop
is the property name (mtime, atime, perm, uid etc..) andop
is the format (optional).
Add file permission to file name:
rnm -ns '/fn/ /info-perm-ls/' ./*
Before | After |
---|---|
dir1 | dir1 drwx--x--x |
perm
is another property for info name string rule,op=ls
is for permission resembling tols
command,oct
is 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
Before | After |
---|---|
dir1/abc.png | dir1/dir1-abc.png |
/pd0/
is the immediate parent directory
rnm -ns '/pd1-0--/-/fn/' dir1/dir0/*.png
Before | After |
---|---|
dir1/dir0/abc.png | dir1/dir0/dir1-dir0-abc.png |
/pd1-0--/
adds the directory names from/pd1/
to/pd0/
with a delimiter in-between./pd0-1- /
would becomedir0 dir1
(here space is the delimiter). The general format is:/pd<from>-<to>-<delimiter>/
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/mt
sorts 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:
- Replace all underscores with hyphen for regular files (
/_/-/gf
). - Replace all dot with hyphen for directories (
/\./-/gd
). - Give all symbolic links a .link extension (
/$/.link/l
).
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' ./*