Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

So far I have a simple batch script that moves *.mkv files from their source folders to a folder called "Movies". Now I would like FileBot to rename them using the 'find' command, since it (filebot) doesn't seem to support regular expressions. How would I have bash pull a file-name-variable (not sure if this is a thing haha) and use it in find -exec "$FILENAME" kind of pattern?

Here is what I have (pseudo is commented out), I'm sure there's a more efficient way to do this. But hey, I'm a python coder NOT a bash scripter!

mkdir "Movies"
find "Complete/" -iname "*.mkv" -exec mv {} "Movies" \;
#find "Movies/" -iname "*.mkv" -exec filebot -rename "$iname" --db themoviedb"

I need the mv and filebot commands to execute separately as eventually more commands will be called between them.

share|improve this question
How do you want to rename? It it just to lowercase the filename? – glenn jackman Dec 30 '12 at 1:39
up vote 1 down vote accepted

Firstly, for the second line, mv takes wildcards too, so you can simply use

mv Complete/*.mkv Movies

Is it possible that filebot also takes wildcards? i.e. filebot Movies/*.mkv? Otherwise, instead of "$iname", you just want {} again. As you probably know, {} substitutes for the name of the file found, which is the same as *.mkv here. Hence,

find "Movies/" -iname "*.mkv" -execdir filebot -rename {} --db themoviedb \;

N.B. use -execdir instead of -exec for security reasons. From the man page:

There are unavoidable security problems surrounding use of the -exec action; you should use the -execdir option instead.

-execdir command {} +

Like -exec, but the specified command is run from the subdirectory containing the matched file, which is not normally the directory in which you started find. This a much more secure method for invoking commands, as it avoids race conditions during resolution of the paths to the matched files.

share|improve this answer
To clarify, it isn't that mv takes wildcards. The shell expands the patterns before it hands the arguments to mv. – glenn jackman Dec 30 '12 at 1:34
Ah nice catch. Hence, I imagine filebot -rename Movies/*.mkv --db themoviedb should work. – Sparhawk Dec 30 '12 at 1:40
This is perfect, thank you. I am using 'find' as the *.mkv files are located in subdirectories. Is there an option to use wildcards with subdirectories? The files can be located at any level.. – user1652011 Dec 30 '12 at 2:43
Glad I could help! I don't think you can use wildcards directly for subdirectories, because it's not like they can substitute for "/" for example. I agree with using find in this case then. Good luck with your script! – Sparhawk Dec 30 '12 at 3:11

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.