Let's say I have a directory with multiple subdirectories, each of which contains some files:
1/a.txt 1/b.txt 2/c.txt 2/d.txt 3/e.txt 3/f.txt
I want to see the size of each file. Please keep in mind, I know there are easier and more direct ways to do this, such as
du -a. I just want to know why the following doesn't work, for educational purposes.
My pointless exercise
find . returns a list of all files and directories, so I tried piping it like so:
find . | xargs du
but that just returns the sizes of the directories 1, 2, and 3. I'm missing some bit of understanding, because in my mind
xargs should be mapping each line of output from
find to a call to
If instead I use:
find . | xargs du -a
then it works as expected, listing the sizes of all files and directories. It also works fine if I only pass it a list of files by using the
-type f option, so it's something to do with receiving a list of directories mixed with files.
What's going on here?