LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   how to find and move a file recursively? (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-find-and-move-a-file-recursively-936576/)

jim.thornton 03-26-2012 08:10 PM

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.

whansard 03-26-2012 08:35 PM

part of the way there
find . -name "*.mp4" -exec grep baby {} \;

suicidaleggroll 03-26-2012 09:04 PM

Something like this?

Code:

find . -iname "*baby*.mp4" -exec handbrake {} \;

TobiSGD 03-26-2012 09:06 PM

Quote:

Originally Posted by whansard (Post 4637145)
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.

jim.thornton 03-27-2012 10:11 AM

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 {}?

suicidaleggroll 03-27-2012 10:19 AM

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.

jim.thornton 03-27-2012 10:52 AM

Thank you for that. How does $file get a value?

while read file

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

TobiSGD 03-27-2012 10:54 AM

Quote:

Originally Posted by jim.thornton (Post 4637788)
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.


All times are GMT -5. The time now is 02:58 AM.