Running wc -l
(line count) individually on a file gives:
λ wc -l pacman_Qemq.txt
235 pacman_Qemq.txt
But running ls | xargs wc -l
gives:
λ ls | xargs wc -l
242409 pacman_database.tar.bz2
235 pacman_Qemq.txt
235 pacman_Qem.txt
807 pacman_Qeq.txt
807 pacman_Qe.txt
376 pacman_Qmq.txt
2276 pacman_Qnq.txt
2276 pacman_Qn.txt
2652 pacman_Qq.txt
2652 pacman_Qsq.txt
2652 pacman_Q.txt
257377 total
How can this be? Why did the total
show up? Why are the entries aligned? Shouldn't xargs
be running wc -l
individually on each file?
Interestingly, wc -l *
produces the same result.
xargs -n 1 wc -l
on the right hand side would not work as soon as a filename contains a space, tab or newline. – Kusalananda Jan 05 '20 at 15:16