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'm using

find . -type f \( -name "*.js" ! -name "*-min*" \) -exec cat {} \; > all.js

to merge files together. Unfortunately I don't get a new line after each file but it ends and the new file starts on the same line.

How can I add a newline between each file?

share|improve this question
up vote 4 down vote accepted

The script below will do the task

find . -type f \( -name "*.js" ! -name "*-min*" \) | while IFS= read -r line
   cat "$line"
done >all.js
share|improve this answer
Perfect! Will accept in 3 min ;) – Asken Sep 5 '12 at 10:39

If you want to systematically add a newline after each file:

find . -type f \( -name "*.js" ! -name "*-min*" \) \
     -exec cat {} \; -exec echo \; > all.js


find . -type f \( -name "*.js" ! -name "*-min*" \) \
     -exec sh -c 'for x; do cat "$x"; echo; done' _ {} + >all.js

If you want to add a newline at the end of each file that doesn't end with a newline:

find . -type f \( -name "*.js" ! -name "*-min*" \) \
     -exec awk '1' {} + > all.js
share|improve this answer
Above and beyond! Thanks! – Asken Sep 7 '12 at 9:40

You can also do this way:

find source/path -name *.js | xargs cat > all.js

share|improve this answer

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.