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

How can I execute a command for file which has address of jar files. The command that I want to execute is jar xf entry.jar. I d like to execute that command and sent the outputs to another file.

Assume my file contains following entries.


What I want is simply extract these jar files and sent the output to another file.

share|improve this question
up vote 7 down vote accepted

I guess what you want is something like this:

xargs -n1 -d'\n' jar xf <list

Where list is the name of the file containing entries.

I'm not sure what you mean by send the outputs to another file. If you want a record of what the jar command prints on the console you can append a >out.log argument at the end.

(The -d option is there in the case filenames contains spaces and are listed one per line.)

share|improve this answer
I tried following command but it didnt work. xargs jar xf < out_file > output2.log. It print "xargs: Could not exec command: No such file or directory" – mibzer Jan 16 '12 at 12:56
Make sure that jar is installed on your system. – Stéphane Gimenez Jan 16 '12 at 13:05
Does not work for me too. I have jar on my system. It silently does nothing. – user unknown Jan 16 '12 at 14:34
The shell part is correct, the jar's syntax is wrong – its first parameter after the command has to be the .jar file's name: xargs -n1 -d'\n' jar xf entry.jar <list. – manatwork Jan 16 '12 at 15:49
manatwork: As I understood it, the provided list contains “.jar” filenames, not paths to be extracted from a single jar. – Stéphane Gimenez Jan 16 '12 at 16:02


for entry in $(<list) ; do jar -xf "$entry"; done > output2.log

works for you?

jar -xf a b [...]

would try to extract b from a, but you want to extract all 3 jars, as far as I can see.

share|improve this answer
What if a filename contain a space? – enzotib Jan 16 '12 at 13:58
More importantly, I missed the dollar sign! :) Yes, jar-files, containing spaces, are pretty rare, and it will not work that way. And if the filenames contain linefeeds, too. – user unknown Jan 16 '12 at 14:32

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.