Why doesn't du or echo pipelining work?

I am trying to use the du command for each directory in the current one. So I am trying to use a code like this:

ls | du -sb

But it does not work as expected. It displays only the size of the current value. catalog and all. The same thing happens with an echo

ls | echo

Prints an empty string. Why is this happening?

+5
source share
3 answers

Using a pipe sends the output (stdout) of the first command to stdin (input) of the child process (second command). The teams you mentioned do not accept any data on stdin. This will work, for example, with cat(and by work, I mean that type work is catperformed without arguments and is simply passed by the input you entered):

ls | cat

xargs. . , :

ls | xargs du -sb

, xargs , , , , . , :

du -sb *
+11

, :

du -sb $(ls -d */)
+3
$ find . -type d -maxdepth 1 -exec du -sb {} \;

or

$ ls -d */ | xargs du -sb
+2
source

All Articles