Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. 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 this command inside a Bash shell script, the intention of which is to apply a java command, htmlcompressor, to each HTML file found in a directory:

find $DIR -type f -name '*.html' -exec java -jar $BASEDIR/Upload/htmlcompressor-1.5.3.jar --remove-intertag-spaces {} \;

However, while the output at the command line seems to indicate that it is finding each file and doing something with it, it's not actually writing the results to the files.

According to the documentation for htmlcompressor, the usage is this:

Usage: java -jar htmlcompressor.jar [options] [input]

So there's supposed to be an input file at the named at the end, but I thought the find command took care of that. Seems I'm wrong about that, though.

What can I do to make it actually act on the files I find?

share|improve this question
up vote 2 down vote accepted

What you've provided seems to be correct; you can verify that java is being invoked correctly by inserting echo into the command:

find $DIR -type f -name '*.html' -exec echo java -jar $BASEDIR/Upload/htmlcompressor-1.5.3.jar --remove-intertag-spaces {} \;

(assuming a properly POSIX compliant system which has non-builtin versions of shell builtins on the standard PATH).

Beyond that, you might want to run one of the resulting commands manually to verify that it is working correctly.

share|improve this answer
Oh, apparently I have to set a parameter, -o, to specify the output file, otherwise it just runs without saving the changes. So... my bad on not seeing that in the documenation. However, how do I get the find command to attach the right input file to the parameter? The command itself needs to be java -jar htmlcompressor.jar -o output.html input.html. I want the input and output to be the same, thus: java -jar htmlcompressor.jar -o same.html same.html. How do I get the find command to do that? – Questioner Apr 8 '12 at 7:38
Will it actually work that way? (This is worth verifying; some programs, when asked to do that, will destroy their input before they have a chance to read it.) If it will, simply specifying the {} wherever it's needed will work. – geekosaur Apr 8 '12 at 7:41
Yep, that works! – Questioner Apr 8 '12 at 7:52

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.