How to save terminal output from multiple files on UNIX?

I have a java class file that I need to run for every file in a directory. I am currently using the following command to run a program for each file in a directory

find . -type f -exec java JavaProgram {} \;

However, instead of displaying the result in the terminal, I need it to output the result of each call to a separate file. Is there a command that I could use that can recursively call a java program in the whole directory and save the terminal output of each call to a separate file?

It looks like a launch java JavaProgram inputfile > outputdir/outputfile, but recursively through each file in the directory, where 'inputfile'they 'outputfile'have the same name.

+3
source share
2 answers

What about

for i in $(find . -type f)
do
    java JavaProgram $i > ${i}.out
done

filename.out . , , , , basename .

+4

, . :

find . -type f -exec sh -c "java JavaProgram {} > outputdir/{}" \;
+2

All Articles