LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   rename files including ones in sub directories (https://www.linuxquestions.org/questions/linux-newbie-8/rename-files-including-ones-in-sub-directories-4175437659/)

nawo69 11-18-2012 04:00 AM

rename files including ones in sub directories
 
Hi I trying to rename files across sub directories but not having much joy.

I want to rename files containing "-trailer.mov" in the name to ".[TRAILER].mov" for example "Filmname (2012)-trailer.mov" would become "Filmname (2012).[TRAILER].mov"

I can do it in the directory containing the file with
rename -v -- "-trailer.mov" ".[TRAILER].mov" *.*
but how would I do it for all sub directories in/i-data/md0/Disk1/Films/

TIA

catkin 11-18-2012 04:13 AM

Code:

#!/bin/bash

IFS=/
for dir in i-data/md0/Disk1/Films
do
    cd $dir && rename -v -- "-trailer.mov" ".[TRAILER].mov" *.*
done


colucix 11-18-2012 04:16 AM

Code:

find /i-data/md0/Disk1/Films/ -name \*-trailer.mov -exec rename "-trailer.mov" ".[TRAILER].mov" {} \+
I've removed the rename command options to adapt the command line to rename available on my system. Anyway, the suggested command line should give you an idea on how to execute a command over multiple files recursively. Note the closing \+ makes the command to be executed once over the files all together. See man find for details.

nawo69 11-18-2012 05:31 AM

Thanks guys the Bash one didn't seem to do anything but the other command after a slight tweak is working perfectly.

:hattip:

catkin 11-18-2012 05:44 AM

Glad you got a solution :)

Threads can be marked SOLVED via the Thread Tools menu.


All times are GMT -5. The time now is 10:06 AM.