Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7966659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:29:13+00:00 2026-06-04T06:29:13+00:00

The following works from the terminal no problem find testDir -type f -exec md5sum

  • 0

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, I get an error using the following in Java

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

The error is

find: missing argument to `-exec'

I believe I am escaping the characters correctly. I have tried several different formats and I cannot get this to work.

UPDATE @jtahlborn answered the question perfectly. But the command has now changed slightly to sort each file in the dir before calculating the md5sum and is as follows (I have already accepted the excellent answer for the original question so I’ll buy somebody a beer if they can come up with the format for this. I have tried every combination I can think of following the answer below with no success.)

“find testDir -type f -exec md5sum {} + | awk {print $1} | sort |
md5sum ;”

NEW UPDATE

For pipe, you need a shell so I ended up with this, which works great and you can still get the output.

Runtime rt = Runtime.getRuntime();
Process pr = rt.exec(new String[] 
{
    "sh", "-l", "-c", "find " + directory.getPath() + " -type f -exec md5sum {} + | awk '{print $1}' | sort | md5sum"
});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T06:29:15+00:00Added an answer on June 4, 2026 at 6:29 am

    use the multi-argument call to exec (otherwise you can get bitten by escape rules). also, since you aren’t calling from a shell script, you don’t need to escape the semicolon:

    Process pr = rt.exec(new String[]{"find", "testDir", "-type", "f", "-exec", "md5sum", "{}", ";"});
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following query that works well. SELECT DISTINCT city,region1,region2 from static_geo_world where
Following works fine in shell: >>> from django.contrib.auth.models import User >>> user=User.objects.get(pk=1) >>> user.first_name
The following code works in all browsers apart from IE6... var mylib = {
The following script works to open Firefox's location/awesome bar from anywhere using control-l ,
I have the following which works in SQL Query Analyzer . select oh.* from
This has to be obtained from a remote machine. The following query works not
I am using dialog plugin from jQuery UI 1.8.17. The following code works and
I have the following PHP code which works out the possible combinations from a
Ive got the following code which I hacked together from website examples. It works
I have the following block of code which works fine; var boughtItemsToday = (from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.