You are not logged in.

#1 2007-08-21 08:27:17

sH
Member
From: Braunschweig, Germany
Registered: 2007-05-02
Posts: 145

Multiple file rename in subfolders?

Hi all,

I want to rename all my ".folder.jpg" in my music folder (because banshee does not recognize them)
to "folder.jpg".
How can I do this from the command line? I know find and mv, but how to combine them?


Thanks alot.

Offline

#2 2007-08-21 08:46:52

lessthanjake
Member
From: Norway
Registered: 2005-11-09
Posts: 319
Website

Re: Multiple file rename in subfolders?

EDIT: this doesn't work!!

Maybe something like this (untested):

find music -name '*jpg' -exec mv '{}' `dirname '{}'`/folder.jpg \;

Last edited by lessthanjake (2007-08-21 08:55:16)

Offline

#3 2007-08-21 08:53:04

shining
Pacman Developer
Registered: 2006-05-10
Posts: 2,043

Re: Multiple file rename in subfolders?

Untested means either backup your music folder first, or change that command sightly, eg with mv -i .

For me, it moved all .folder.jpg to folder.jpg in the current working directory. So it seems to overwrite the files, letting you with only one.


pacman roulette : pacman -S $(pacman -Slq | LANG=C sort -R | head -n $((RANDOM % 10)))

Offline

#4 2007-08-21 08:54:03

lessthanjake
Member
From: Norway
Registered: 2005-11-09
Posts: 319
Website

Re: Multiple file rename in subfolders?

Last one wouldn't work! But this shuould:
But as alway be careful when doing stuff like this, I would dryrun once with mv changed to echo or as mentioned with the -i flag on mv.

find musikk -name '*jpg' |while read f; do mv "$f" `dirname "$f"`/folder.jpg; done

Last edited by lessthanjake (2007-08-21 08:59:54)

Offline

#5 2007-08-21 09:12:06

shining
Pacman Developer
Registered: 2006-05-10
Posts: 2,043

Re: Multiple file rename in subfolders?

That seems to work better. Just added "" that should make it work with dirnames containing space

find bla -name '.folder.jpg' |while read f; do mv -i "$f" "`dirname "$f"`"/folder.jpg; done

Last edited by shining (2007-08-21 09:13:16)


pacman roulette : pacman -S $(pacman -Slq | LANG=C sort -R | head -n $((RANDOM % 10)))

Offline

#6 2007-08-21 09:13:47

morellik
Member
From: Italy
Registered: 2007-04-05
Posts: 43

Re: Multiple file rename in subfolders?

Surely someone has a better solution.
You write the following code in a file and execute it changing its mode in 755.

f=`find  . -type f -name ".*" -print | cut -d. -f3`
for i in `echo $f`
do
  mv .$i.jpg $i.jpg
done

Offline

#7 2007-08-21 10:46:03

sH
Member
From: Braunschweig, Germany
Registered: 2007-05-02
Posts: 145

Re: Multiple file rename in subfolders?

Both versions work, thank you very much. (The commands work surprisingly fast although i have a large library)

Offline

#8 2007-08-21 10:57:28

shining
Pacman Developer
Registered: 2006-05-10
Posts: 2,043

Re: Multiple file rename in subfolders?

morellik wrote:

Surely someone has a better solution.
You write the following code in a file and execute it changing its mode in 755.

f=`find  . -type f -name ".*" -print | cut -d. -f3`
for i in `echo $f`
do
  mv .$i.jpg $i.jpg
done

I think this one would only work for files on the first level.
In this case, don't use find, but rather something like :

for i in .*.jpg; do mv $i ${i#.*}; done

pacman roulette : pacman -S $(pacman -Slq | LANG=C sort -R | head -n $((RANDOM % 10)))

Offline

#9 2007-08-22 07:36:03

morellik
Member
From: Italy
Registered: 2007-04-05
Posts: 43

Re: Multiple file rename in subfolders?

shining wrote:
morellik wrote:

Surely someone has a better solution.
You write the following code in a file and execute it changing its mode in 755.

f=`find  . -type f -name ".*" -print | cut -d. -f3`
for i in `echo $f`
do
  mv .$i.jpg $i.jpg
done

I think this one would only work for files on the first level.
In this case, don't use find, but rather something like :

for i in .*.jpg; do mv $i ${i#.*}; done

Yes, of course. Thanks for the improvements.

Offline

#10 2007-12-26 09:46:38

Micha
Member
Registered: 2007-11-16
Posts: 20

Re: Multiple file rename in subfolders?

Although you already have a solution, here's another option using mmv: http://aur.archlinux.org/packages.php?d … ns=&SeB=nd and http://linux.die.net/man/1/mmv. Don't know if that helps though but... good luck.
Micha

Offline

Board footer

Powered by FluxBB