You are not logged in.

#1 2012-08-06 10:44:08

Lockheed
Member
Registered: 2010-03-16
Posts: 1,521

[solved] Batch rename

I have some .png file and I need to remove from all of them a filename part containing '.mdl' (this is not an extension). I tried running a find command

find . -type f -exec rename 's/\ \(.mdl\)$//' {} \;

but it tells me there is not enough arguments.

Last edited by Lockheed (2012-08-06 11:58:13)

Offline

#2 2012-08-06 10:51:30

ebal
Member
From: Athens, Greece
Registered: 2009-05-26
Posts: 224
Website

Re: [solved] Batch rename

why using find ?

rename ".mdl" "" *

https://balaskas.gr
Linux System Engineer - Registered Linux User #420129

Offline

#3 2012-08-06 11:06:47

tomk
Forum Fellow
From: Ireland
Registered: 2004-07-21
Posts: 9,839

Re: [solved] Batch rename

Correct. Also, your first attempt failed for two reasons, the first being your use of sed syntax yikes , the second being that rename requires three arguments, not two. rename -h helps here.

Offline

#4 2012-08-06 11:23:32

Lockheed
Member
Registered: 2010-03-16
Posts: 1,521

Re: [solved] Batch rename

ebal wrote:

why using find ?

rename ".mdl" "" *

Lol. KISS. Thanks.

Offline

#5 2012-08-06 11:49:01

DSpider
Member
From: Romania
Registered: 2009-08-23
Posts: 2,273

Re: [solved] Batch rename

For recursive renaming in multiple folders:

$ cd /parent/folder
$ rename ".mdl" "" */*

Don't forget to mark it as solved.


"How to Succeed with Linux"

I have made a personal commitment not to reply in topics that start with a lowercase letter. Proper grammar and punctuation is a sign of respect, and if you do not show any, you will NOT receive any help (at least not from me).

Offline

#6 2012-08-06 12:07:18

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: [solved] Batch rename

DSpider wrote:

For recursive renaming in multiple folders:

$ cd /parent/folder
$ rename ".mdl" "" */*

No, you need globstar (**)

shopt -s globstar
rename ".mdl" "" **.png

Offline

#7 2012-08-06 16:46:44

drcouzelis
Member
From: Connecticut, USA
Registered: 2009-11-09
Posts: 4,092
Website

Re: [solved] Batch rename

Procyon wrote:

No, you need globstar (**)

shopt -s globstar
rename ".mdl" "" **.png

I had no idea about globstars. MY WHOLE LIFE HAS BEEN TURNED UPSIDE DOWN

...Another option I learned about kind of recently is "vidir", found in the "moreutils" package. It's like using vim on a directory!

Offline

#8 2015-05-15 12:59:22

triplc
Member
From: Hanoi, Vietnam
Registered: 2009-08-23
Posts: 39

Re: [solved] Batch rename

I had the same problem... and at last I found WHY.

The command "rename" in Archlinux is different from the command "rename" in Debian/Ubuntu.

If you want to use "rename <perl replacement> file..." in Archlinux then install the package "perl-rename", and run "perl rename <perl replacement> file..."

Offline

#9 2015-05-15 13:35:02

WorMzy
Forum Moderator
From: Scotland
Registered: 2010-06-16
Posts: 11,873
Website

Re: [solved] Batch rename

That information would be better placed on the wiki, rather that a three year old solved thread.

Please don't necrobump.

Closing.


Sakura:-
Mobo: MSI MAG X570S TORPEDO MAX // Processor: AMD Ryzen 9 5950X @4.9GHz // GFX: AMD Radeon RX 5700 XT // RAM: 32GB (4x 8GB) Corsair DDR4 (@ 3000MHz) // Storage: 1x 3TB HDD, 6x 1TB SSD, 2x 120GB SSD, 1x 275GB M2 SSD

Making lemonade from lemons since 2015.

Offline

Board footer

Powered by FluxBB