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

The following works from the terminal no problem

find testDir -type f -exec md5sum {} \;

Where testDir is a directory that contains some files (for example file1, file2 and file3).

However, if I run this from a bash script or from Java using something like

Runtime rt = Runtime.getRuntime();
Process pr = rt.exec("find testDir -type f -exec md5sum {} \\;");

I get the following error

find: missing argument to `-exec'

Any ideas?

UPDATE: This was answered correctly over on stackoverflow. I will close the question here.

share|improve this question
Could you post a complete example that can be pasted and run? – 0xC0000022L May 22 '12 at 15:15
up vote 4 down vote accepted

The \ in -exec md6sum {} \; is necessary to prevent the shell from interpreting the ; character as command separator. If Java does not execute the command in a shell, try removing the escaping \\ so that the code becomes:

Runtime rt = Runtime.getRuntime();
Process pr = rt.exec("find testDir -type f -exec md5sum {} ;");

I have just confirmed this behavior with the next test program:

class Xx {
    public static void main(String args[]) throws Exception {
        Process p = Runtime.getRuntime().exec("/bin/echo \\;");
        InputStream in = p.getInputStream();
        int c;
        while (( != -1)

Compiled with javac, java Xx outputs \;. If I remove the \\, it'll print ; as expected.

share|improve this answer

Different shells sometimes require different characters to be escaped, so depending on what shell you are using in your terminal and what shell you are using for your script (you say bash, but are you sure?), you can get different results. Zsh, for example, will require you to escape the {} too:

find testDir -type f -exec md5sum \{\} \;

From Java, you could try removing all the backslashes or changing your second line to:

Process pr = rt.exec("find testDir -type f -exec md5sum \\{\\} \\;");
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.