Sunday, May 19, 2013

Concatenating thousands of files: > vs >>

Concatenating thousands of files: > vs >>

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. However, the second answer has more votes (10) and was also accepted with no comments. Are both answers correct? Why?

No comments:

Post a Comment