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 have the following directory structure:


I am using the find command to get to all the .po files and apply the msgfmt command to them.

So when I run this command:

find . -name \*.po

The output is


Just as expected but now I when I add this:

find . -name \*.po -exec msgfmt "{}" \;

It outputs nothing and it does not create the .mo files it is supposed to (If I do it to each file individually the msgfmt command works as expected).

This is weird since if I change the command to this:

find . -name *.po -exec echo "{}" \;

It outputs the names of the files correctly.

I've sort of solved it like this:

find . -name \*.po -exec msgfmt "{}" -o {}.mo \;

But it outputs a

How can this be done?

share|improve this question
up vote 6 down vote accepted

How about -execdir?

This differs from -exec in that it runs the command from the same directory that it finds the files (rather than the current working directory). Given that you're only going to find one translation.po file in your LC_MESSAGES directories, we can lock things right down and not have to fuss around trying to snap the extension off the end of the path.

find . -name \*.po -execdir msgfmt translation.po -o \;
share|improve this answer
Awesome :) Works like a charm, I'll accept as soon as I can... – Trufa Apr 10 '13 at 16:11

I am using something like this:

find . -name \*.po -execdir sh -c 'msgfmt "$0" -o `basename $0 .po`.mo' '{}' \;

This also removes *.po extension and add *.mo extension.

share|improve this answer

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.