I need to rename a bunch of files in order to fix their sort order, therefore I need to be able to do a sort of "find and replace" so I can replace chunks of the filenames at a time.
What tools should I use? I prefer GUI but a command line tool recommendation would also be fine.
There are a few but I recommend gprename which is a good compromise between usability and functionality.
Other tools are: rename, krename , pyrenamer , cuteRenamer, ...
I really like qmv from the
renameutils
package. It enables you to use your favorite (terminal based) text editor to rename files. I prefer to invoke it with-f do
which gives you a single column (one row per file) with filenames. Combined with the power of Vim it gives you all the tools you need to do massive filename editing.http://www.nongnu.org/renameutils/
Métamorphose
https://github.com/metamorphose
may be a little difficult to handle, but really powerful!
If you like the shell and perl regular expressions I'd recommend
rename
. It's as plain as it's name.thunar file manager is a GUI with a bulk rename option
http://thunar.xfce.org/pwiki/documentation/bulk_renamer
it's not standard on Gnome but can be installed through the software centre
If you are familiar with Emacs, I think nothing beats Dired for this task. Even if you don't use Emacs that often you may find Dired a handy tool.
sudo aptitude install emacs23-nox
Start Emacs Dired mode for a directory:
emacs -nw path/to/dir/
Now enter edit directory mode:
C-x C-q
(that is Ctrl+x followed by Ctrl+q)You can now edit the filenames like editing text in every plain text editor. You may even chose to replace the filenames using regular expressions (note that unfortunately Emacs uses a different syntax than PCRE).
For example, to rename files with counter (starting by 1):
M-x replace-regexp
(that is Alt+x followed by the string "replace-regexp" typed in the minibuffer at the bottom of the screen).Replace regexp:
DSCN\([0-9]+\).JPG
Replace with:
\,(format "P%04d.jpg" (1 + \#))
To reuse a counter in the filename:
M-x replace-regexp
Replace regexp:
DSCN\([0-9]+\).JPG
Replace with:
\,(format "P%04d.jpg" (string-to-number \1))
When finished, type:
C-c C-c
(that is Ctrl+c followed by Ctrl+c)Or alternatively press the following sequence to abort your changes:
C-c Esc
(that is Ctrl+c followed by Esc)I tend to use mmv, which is command-line based, and has a somewhat quirky expression syntax but tend to solve most of my problems.
If you use Nautilus and know how Nautilus Scripts work, you could use nautilus-renamer.
find -execdir rename
This renames files and directories with a regular expression affecting only basenames, for example:
or to affect files only:
I have explained it in more detail at: https://stackoverflow.com/questions/16541582/find-multiple-files-and-rename-them-in-linux/54163971#54163971
On the command line theres also the possibility to use magic of sed and shell: