I have folder with several hundred files named like this:
010203.txt
I want to rearrange the file names so that last two digits are moved to the front like this:
030102.txt
I want to avoid writing a script.
Instead, I'm looking for a "linux gui regular expression file renamer" that can recursively evaluate all files in a folder (and its sub-folders).
I want the ability to specify a regular expression for matching a file:
(\d\d)(\d\d)(\d\d)(.*)
And I want the ability to perform regular expression substitution to rename the file:
$3$1$2$4
Any suggestion?
05 Answers
I realize this is not exactly a "GUI", but you didn't say anything why that is a requirement, and there are already-written command-line tools that do this; e.g. perl-rename:
find ~/dir -type f -exec prename -n 's/^(\d\d)(\d\d)(\d\d)(.*)$/$3$1$2$4/' {} +(-n turns on "test" mode. When you're satisfied with the output, run again with -v or no options instead.)
Some good GUI tools for renaming files are
- KRename for KDE desktop environment (I personally prefer this one because I'm a KDE user);
- GPRename and pyRenamer for Gnome.
A combination of renameutils and your favorite regex editor (gedit, sublime, atom) might be the easiest way to go.
- Install rename utils:
sudo apt install renameutilsor
sudo pacman -Syu renameutilsRun
qmvwith your favorite editor:2.1 Sublime:
qmv -f do -e "subl -w" ./PATH/TO/FILES2.2 Atom:
qmv -f do -e "atom -w" ./PATH/TO/FILES2.3 Gedit:
qmv -f do -e "gedit" ./PATH/TO/FILESUse the editor full regex capabilities (including multiselection / and
Ctrl+D) to create the list of new names.Save & Close
I appreciate the suggestions, but I found an easier way, using a graphical user interface.
In Ubuntu, install thunar:
sudo apt-get install thunarThen all you have to do is navigate to a folder (with thunar) and hit ctrl-a to select all files in that folder.
After this, right-click on one of the files (you've highlighted), and select "rename" from the context menu. Then, this dialog pops up, allowing you to do regular expression substitution for renaming.
This doesn't meet the recursive requirement I mentioned, but for changing the names of all files within a single folder, its a lot simpler than the command line, but actually, I do appreciate both methods.
3XFCE's Thunar file manager have nice mass renamer feature.
Just select more than one file and hit F2 to show Rename Multiple Files dialog.
From the drop down menu select Search & Replace option, check [x] Regular Expression checkbox and type Search and Replace criteria.
For example I've got several files from DVB-T grabber named
20190813 Okno do New Yorku.avi
20190814 Okno do Rima.avi
20190815 Okno do Bankoku.avi
20190820 Okno do Hamburgu.aviUsing search ([0-9]+) (.*) and replace DOC \2 \1 the transformation creates
DOC Okno do New Yorku 20190813.avi
DOC Okno do Rima 20190814.avi
DOC Okno do Bankoku 20190815.avi
DOC Okno do Hamburgu 20190820.aviwhich is very cool.
The mass renamer also have live preview so you can see the matched lines and their transformation next to source filenames which is good for debugging the regexp. The unmatched filenames are not changed.