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

I'm new to Linux and I want to execute one command on every file in a loop:

avconv -i *.mp4 -vcodec copy -ac 2 -strict experimental *.mp4

Can any one tell me how I can do this? I have more than 100 files to convert. I just want to convert them into new files with the same names, but using different codecs. It works for one file but I don't know how to run it on all of the files. I found this avconv documentation but I can't find the answer in there either.

share|improve this question
up vote 18 down vote accepted

Try this:

for i in *.mp4; do avconv -i "$i" -vcodec copy -ac 2 -strict experimental "out-$i"; done
share|improve this answer
In case of files with spaces, instances of $i usually need to be "quoted". – user76204 Oct 22 '12 at 14:52
yes, you are right; corrected. – January Oct 22 '12 at 16:19
And it should be "out-$i" instead of "out-$i.mp4" unless you want to get files with *.mp4.mp4 extension ;) – Piotr Kukielka Apr 4 '15 at 14:07

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.