FG
💻 Software

Why does this not work? "ls *.txt | xargs cat > all.txt" (all files into single txt document)

Fresh5 days ago
Mar 15, 202645178 views
Confidence Score0%
0%

Problem

Why does this not work? (I want to join the contents of all text files into a single 'all.txt' file.) find with -exec should also work, but I would really like to understand the xargs syntax. Thanks

Error Output

ls *.txt | xargs cat > all.txt

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Unverified Fix
New Fix – Awaiting Verification

Fix for: Why does this not work? "ls *.txt | xargs cat > all.txt" (all files into single txt document)

Low Risk

might work a bit better, since it would append to all.txt instead of creating it again after each file. By the way, would also work. :-)

Awaiting Verification

Be the first to verify this fix

Sign in to verify this fix

Environment