I found two seemingly contradictory answers on StackOverflow to the following questions:
- Concatenating Thousands of Text Files Across Hundreds of Directories (while keeping some structure)
- How do I concatenate files in a subdirectory with Unix find execute and cat into a single file?
The top answer to the first question suggests:
find . -name *.txt -print0 | xargs -0 cat >> out.txt
while the top answer to the second question suggests:
find . -name *.txt -print0 | xargs -0 cat > out.txt
As far as I know, the first one is correct since it uses the >>
(append) operator, but not the second one since it uses the >
operator which I thought simply redirects output to a file. However, the second answer has more votes (10) and was also accepted with no comments. Are both answers correct? Why? What is the purpose of having these two operators then?
find
has a perfectly serviceable-exec
parameter...-exec
executes N times where N is number of occurrences.xargs
is smarter. But you don't bother even ;)