LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
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 03-26-2012, 09:10 PM   #1
jim.thornton
Member
 
Registered: May 2007
Posts: 404

Rep: Reputation: 19
how to find and move a file recursively?


I'm trying to search through a media directory which has a number of sub-directories for any files with a specified string "baby" in them which all end in .mp4 extension. I would then like to either move those files to a specific directory or run handbrake from the commandline to convert them to *.avi (preferrably the latter).

Can anyone help me with a bash command line argument that will do this?

I'm thinking of using the find command and then piping the result into exec running handbrake on the found filename, but I'm not sure of the syntax.
 
Old 03-26-2012, 09:35 PM   #2
whansard
Senior Member
 
Registered: Dec 2002
Location: Mosquitoville
Distribution: RH 6.2, Gen2, Knoppix,arch, bodhi, studio, suse, mint
Posts: 3,185

Rep: Reputation: 52
part of the way there
find . -name "*.mp4" -exec grep baby {} \;
 
Old 03-26-2012, 10:04 PM   #3
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,260

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
Something like this?

Code:
find . -iname "*baby*.mp4" -exec handbrake {} \;
 
Old 03-26-2012, 10:06 PM   #4
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,130
Blog Entries: 2

Rep: Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825
Quote:
Originally Posted by whansard View Post
part of the way there
find . -name "*.mp4" -exec grep baby {} \;
Would be easier this way
Code:
find . -name "*baby*.mp4" -exec handbrake HANDBRAKEOPTIONSHERE \;
I don't know anything about handbrake, so I can't recommend any options. Keep in mind that the name of the found file can be given to handbrake with the {} parameter, for example (assuming that -if specifies the input-file) handbrake -if \{} (the braces have to be escaped, so that they are not interpreted from the shell.
 
Old 03-27-2012, 11:11 AM   #5
jim.thornton
Member
 
Registered: May 2007
Posts: 404

Original Poster
Rep: Reputation: 19
Thank you for the help. Question: I have figured out the Handbrake commands and I have figured out the above commands that you suggested. There is only one issue.

Input name: baby-christmas-2011.mp4
Output name: baby-christmas-2011.mkv

How can I just change the .mp4 to mkv when the {} returns "baby-christmas-2011.mp4"? Is it possible to manipulate it while using {}?
 
Old 03-27-2012, 11:19 AM   #6
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,260

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
There might be a way to do that within -exec, but if it were me I would probably just modify the command a bit for that:

Code:
find . -name "*baby*.mp4" | while read file; do
   handbrake -i "$file" -o "${file/.mp4/.mkv}"
done
Or on one line:
Code:
find . -name "*baby*.mp4" | while read file; do handbrake -i "$file" -o "${file/.mp4/.mkv}"; done
Naturally you'd need to modify the arguments to handbrake as necessary, since I have no idea how it's called.

Last edited by suicidaleggroll; 03-27-2012 at 11:20 AM.
 
Old 03-27-2012, 11:52 AM   #7
jim.thornton
Member
 
Registered: May 2007
Posts: 404

Original Poster
Rep: Reputation: 19
Thank you for that. How does $file get a value?

while read file

Is this where it is loading the file name into $file?
 
Old 03-27-2012, 11:54 AM   #8
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,130
Blog Entries: 2

Rep: Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825
Quote:
Originally Posted by jim.thornton View Post
Thank you for that. How does $file get a value?

while read file

Is this where it is loading the file name into $file?
Exactly.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Recursively move files michaelsanford Linux - General 5 02-17-2016 02:24 AM
[SOLVED] find maximum length file in a directory recursively using shell scripting sudeep_mansh Programming 6 11-19-2010 12:52 PM
Recursively move files one directory up FLX Linux - Newbie 8 10-06-2009 02:41 PM
find and move to folder and file dulahdaglace Linux - Newbie 1 09-15-2009 11:44 PM
Perl help - recursively find non-ascii characters in file zeky Linux - General 4 01-07-2009 08:38 PM


All times are GMT -5. The time now is 03:50 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration