[Mageia-discuss] Debian-style «rename» utility?
Renaud (Ron) Olgiati
renaud at olgiati-in-paraguay.org
Wed Jan 2 01:13:02 CET 2013
On Tuesday 01 Jan 2013 17:58 my mailbox was graced by a message from Johnny A.
Solbu who wrote:
> Sometimes I need to mass rename filenames, to replace norwegian special
> caracters, to make things work across samba. On Debian th rename utility
> user «sed» style replacements, which means one command can replace all
> instances of a character or string recursively in all subfolders. But on
> Mandriva and Mageia, I have to run the exact same command multiple times
> in the same folder to do the same thing. And I can't do it recursively.
>
> One example. Say I want to recursively replace all spaces ' ' with an
> underscore '_' on all files in every subfolder under «folder2»
>
> On Debian:
> replace 's/\ /_/g' folder2/
>
> On Mageia:
> cd folder2
> replace ' ' '_' *
> replace ' ' '_' *
> replace ' ' '_' *
> replace ' ' '_' *
>
> cd subfolder1
> replace ' ' '_' *
> <repeating>
> <repeating>
> ......
> and so on.
>
> Is there a command line utility on Mageia that can do this te way Debian
> does this, without resorting to creating a shellscript each time I need to
> replace something? (I'm no good at scripting, so I've had to do this
> manually for some 11 years.)
I have been removing spaces and a number of characters that cause problems in
filenames with the following:
#!/bin/bash
ls | grep " " >totototo
while [ -s totototo ]
do
rename " " _ *" "*
ls | grep " " >totototo
done
for CHR in "(" ")" "," "%" "'" ":" ";" "__" "_-"
do
ls | grep $CHR >totototo
while [ -s totototo ]
do
rename $CHR "" *$CHR*
ls | grep $CHR >totototo
done
rm -f totototo
done
echo "Finished !"
Forgot why the space character is treated apart from the others, but ISTR that
the for would not work if $CHR was a space.
Cheers,
Ron.
--
The ability to speak several languages is an admirable asset,
but to be able to hold your tongue in one language is absolutely priceless.
-- http://www.olgiati-in-paraguay.org --
More information about the Mageia-discuss
mailing list