Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

Batch rename

Programming languages, Coding, Executables, Package Creation, and Scripting.
Post Reply
Message
Author
User avatar
sunrat
Administrator
Administrator
Posts: 6479
Joined: 2006-08-29 09:12
Location: Melbourne, Australia
Has thanked: 118 times
Been thanked: 474 times

Batch rename

#1 Post by sunrat »

I admit I will never understand regular expressions. Just spent way too long at first in Double Commander Multi Rename Tool and then with rename utility on cli.
I have a directory of audio files downloaded from Youtoob with names like this:
'01 - All Of My Days [toWgmfI5FRA].opus'
'02 - Emily [XrTJ0NIcTDE].opus'
'03 - Ballad Of A Young Man (Official Music Video) [ZdM9ZEltjEs].opus'
I just want to batch remove the bits between square brackets plus the preceding space. More of a learning exercise now than a vital process but I can't let it defeat me! :mrgreen:
“ computer users can be divided into 2 categories:
Those who have lost data
...and those who have not lost data YET ”
Remember to BACKUP!

arzgi
Posts: 1194
Joined: 2008-02-21 17:03
Location: Finland
Been thanked: 31 times

Re: Batch rename

#2 Post by arzgi »

Code: Select all

 aptitude search rename
p   arename                         - automatic audio file renaming tool        
p   autorenamer                     - program to rename files to make them sort 
p   caja-rename                     - Batch renaming extension for Caja         
p   golang-github-google-renameio-d - provides a way to atomically create or rep
p   gprename                        - Complete batch renamer for Linux          
p   ifrename                        - Rename network interfaces based on various
p   krename                         - powerful batch renamer for KDE            
p   libdevel-caller-ignorenamespace - module for hiding namespaces from caller()
v   libfile-rename-perl             -                                           
p   mp3rename                       - Rename mp3 files based on id3tags         
p   mrename                         - tool for easy and automatic renaming of ma
p   node-gulp-rename                - gulp pulgin to rename files               
p   rename                          - Perl extension for renaming multiple files
p   rename-flac                     - CLI tool to rename FLAC files             
p   renameutils                     - Programs to make file renaming easier   
GUI versions offer the preview option, which is good if don't know regular expressions.

There are books of the regular expressions, if you want to study :D

User avatar
4D696B65
Site admin
Site admin
Posts: 2696
Joined: 2009-06-28 06:09
Been thanked: 86 times

Re: Batch rename

#3 Post by 4D696B65 »

gprename

User avatar
sunrat
Administrator
Administrator
Posts: 6479
Joined: 2006-08-29 09:12
Location: Melbourne, Australia
Has thanked: 118 times
Been thanked: 474 times

Re: Batch rename

#4 Post by sunrat »

Thanks but I know how to search for programs. DC Multi Rename has previews and can use regular expressions but I referred to the guide a few times but couldn't work out the correct one. I ended up removing the last 14 characters in each filename rather than regex. DC was not working with [N1:-15] name mask although I'm sure it worked before so I eventually used rename:

Code: Select all

rename -n 's/.{14}(\.opus)/$1/' *
-n is for dry run of course.

Edit - Explanation for posterity

s/old/new/' replace oldwithnew`
(\.opus) save these characters...
.{14} the last 14 characters whatever they are
$1 the characters saved with ()

One day I'd love to work out how to do it with regex wildcards or similar but I fear I will die trying.
“ computer users can be divided into 2 categories:
Those who have lost data
...and those who have not lost data YET ”
Remember to BACKUP!

User avatar
sunrat
Administrator
Administrator
Posts: 6479
Joined: 2006-08-29 09:12
Location: Melbourne, Australia
Has thanked: 118 times
Been thanked: 474 times

Re: Batch rename

#5 Post by sunrat »

4D696B65 wrote: 2021-12-19 12:43gprename
Will check that one out.

Edit several minutes later - seems to work ok for removing a number of characters as I did in that rename command, but the regex still eludes me.
“ computer users can be divided into 2 categories:
Those who have lost data
...and those who have not lost data YET ”
Remember to BACKUP!

arzgi
Posts: 1194
Joined: 2008-02-21 17:03
Location: Finland
Been thanked: 31 times

Re: Batch rename

#6 Post by arzgi »

There was also krename in the list.

User avatar
sunrat
Administrator
Administrator
Posts: 6479
Joined: 2006-08-29 09:12
Location: Melbourne, Australia
Has thanked: 118 times
Been thanked: 474 times

Re: Batch rename

#7 Post by sunrat »

arzgi wrote: 2021-12-19 12:59 There was also krename in the list.
I had that already and tried it. Still couldn't work out the regex to remove the string "[xcharacters]"

DC has a comprehensive page on regex it uses - https://doublecmd.github.io/doc/en/regexp.html
“ computer users can be divided into 2 categories:
Those who have lost data
...and those who have not lost data YET ”
Remember to BACKUP!

arzgi
Posts: 1194
Joined: 2008-02-21 17:03
Location: Finland
Been thanked: 31 times

Re: Batch rename

#8 Post by arzgi »

Odd, but I believe if you say so. I use xfce, and will not install kdelibs just to test.

User avatar
canci
Global Moderator
Global Moderator
Posts: 2502
Joined: 2006-09-24 11:28
Has thanked: 136 times
Been thanked: 136 times

Re: Batch rename

#9 Post by canci »

I know this might not be the right workflow, but since I use ranger, I'd just mark all songs and use its :bulkrename command.
This actually opens vim and all selected files are shown as 1 file per line. Then I'd just make a quick macro that searches for [, deletes everything within the [], then deletes the [] and moves on to the next line. Then I'll just tell vim to repeat that macro as many times as there are files. When I save and quit vim, ranger renames the files appropriately. If my vim foo were better, I'd permanently store that macro for future use in my .vimrc.
Image Stable / Asus VivoBook X421DA / AMD Ryzen 7 3700U / Radeon Vega Mobile Gfx (Picasso) / 8 GB RAM / 512GB NVMe

READ THIS:

* How to Post a Thread Here
* Other Tips and Great Resources

User avatar
dilberts_left_nut
Administrator
Administrator
Posts: 5346
Joined: 2009-10-05 07:54
Location: enzed
Has thanked: 13 times
Been thanked: 66 times

Re: Batch rename

#10 Post by dilberts_left_nut »

Code: Select all

rename -n 's/\ \[.*\]//' *
maybe (untested).
AdrianTM wrote:There's no hacker in my grandma...

User avatar
oswaldkelso
df -h | grep > 20TiB
df -h | grep > 20TiB
Posts: 1495
Joined: 2005-07-26 23:20
Location: UK
Has thanked: 1 time
Been thanked: 60 times

Re: Batch rename

#11 Post by oswaldkelso »

I use ThunarBulkRename and it's superb the only reason I install Thunar at all. Unfortunately apparently it's quite tied to Thunar as one of the Dragora devs looked at splitting it away.

On window managers I usually stick a keybind on it, as on my non Debian systems it lives in /usr/lib/ThunarBulkRename

I'm glad you brought this up as I'm trying to switch to mc as I'm trying to setup a non gui system and need to try and get batch rename working in there. Something to try tonight.
Free Software Matters
Ash init durbatulûk, ash init gimbatul,
Ash init thrakatulûk agh burzum-ishi krimpatul.
My oldest used PC: 1999 imac 333Mhz 256MB PPC abandoned by Debian

User avatar
canci
Global Moderator
Global Moderator
Posts: 2502
Joined: 2006-09-24 11:28
Has thanked: 136 times
Been thanked: 136 times

Re: Batch rename

#12 Post by canci »

oswaldkelso wrote: 2021-12-19 19:33 I'm glad you brought this up
Yeah, so am I! Thanks for the very interesting topic!
Image Stable / Asus VivoBook X421DA / AMD Ryzen 7 3700U / Radeon Vega Mobile Gfx (Picasso) / 8 GB RAM / 512GB NVMe

READ THIS:

* How to Post a Thread Here
* Other Tips and Great Resources

User avatar
sunrat
Administrator
Administrator
Posts: 6479
Joined: 2006-08-29 09:12
Location: Melbourne, Australia
Has thanked: 118 times
Been thanked: 474 times

Re: Batch rename

#13 Post by sunrat »

dilberts_left_nut wrote: 2021-12-19 19:26

Code: Select all

rename -n 's/\ \[.*\]//' *
maybe (untested).
Perfect, exactly the answer I needed. I even now understand what each part does! Thanks, dln. :wink: 8)

Code: Select all

\ \[.*\]
works as the regex in Double Commander Multi Rename Tool as well. :) I was just missing the dot when I tried it earlier. :oops:
That tool is very similar to Thunar's Bulk Rename which I liked when using MX Linux with Xfce several years ago and is the prime reason I installed Double Commander. I've returned to my old favourite DE KDE Plasma now and wasn't going to install Thunar just for that as it was the only thing I liked about Thunar.
“ computer users can be divided into 2 categories:
Those who have lost data
...and those who have not lost data YET ”
Remember to BACKUP!

User avatar
oswaldkelso
df -h | grep > 20TiB
df -h | grep > 20TiB
Posts: 1495
Joined: 2005-07-26 23:20
Location: UK
Has thanked: 1 time
Been thanked: 60 times

Re: Batch rename

#14 Post by oswaldkelso »

mmv is in the repos Old but Nice as they say. Not sure if I'm talking about the software or myself. Probably just drunk to much Whisky :mrgreen:
Free Software Matters
Ash init durbatulûk, ash init gimbatul,
Ash init thrakatulûk agh burzum-ishi krimpatul.
My oldest used PC: 1999 imac 333Mhz 256MB PPC abandoned by Debian

Post Reply