LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-18-2012, 04:00 AM   #1
nawo69
LQ Newbie
 
Registered: Nov 2012
Distribution: FFP
Posts: 2

Rep: Reputation: Disabled
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
 
Old 11-18-2012, 04:13 AM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Code:
#!/bin/bash

IFS=/
for dir in i-data/md0/Disk1/Films
do
    cd $dir && rename -v -- "-trailer.mov" ".[TRAILER].mov" *.*
done
 
Old 11-18-2012, 04:16 AM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
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.
 
1 members found this post helpful.
Old 11-18-2012, 05:31 AM   #4
nawo69
LQ Newbie
 
Registered: Nov 2012
Distribution: FFP
Posts: 2

Original Poster
Rep: Reputation: Disabled
Thanks guys the Bash one didn't seem to do anything but the other command after a slight tweak is working perfectly.

 
Old 11-18-2012, 05:44 AM   #5
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Glad you got a solution

Threads can be marked SOLVED via the Thread Tools menu.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Trying to write a script to rename files in directories to include directory name kmkocot Linux - Newbie 2 11-15-2011 09:42 PM
Looking for easy way to rename MP3 tags then sort files into directories thethinker Linux - Software 3 08-22-2010 10:47 PM
Build Project is not including the included directories in Kdevelop 4 avanindra Programming 2 09-27-2009 05:33 PM
Tar including all parent directories? everythingand2 Linux - General 4 12-14-2003 06:31 PM
Including other directories g++ & gtk The Yeti Lives Linux - Newbie 2 06-11-2003 08:21 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:20 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration