How to display the file contents recursively?

Solution 1:

You can use find (man page) to accomplish this:

find -name "*.java" -exec cat {} \;

You can also add a -print before the -exec to print the file name before each cat operation

Solution 2:

find . -name "*.java" -print0 | xargs -0 cat 

Solution 3:

shopt -s globstar
cat **/*.java >> all_course.txt

That all_course file will be a bit of a mess. You probably want to add in some headers or footers:

for f in **/*.java; do
    echo "/* *********************************"
    echo " * $f"
    echo " * *********************************/"
    echo ""
    cat "$f"
    echo ""
    echo "/* *********************************"
    echo " * $f"
    echo " * *********************************/"
    echo ""
    echo ""
done > all_course.txt

Solution 4:

find . -name "*.java" -exec cat {} \;

Solution 5:

 grep -R -win --include='*\.java' '' * | less

Will show line no. also, for easy reading. Manipulate with grep switches for better results.