Reputation: 298
I'm trying to find out the total size of a tree inside a file-system which also includes any files and sub-directories recursively. And I found somethings online when I searched for it.
First i found something I think I can use to search through a tree recursively which is:
find . -type f | wc -l
And then I found this:
du -hs
Which should summarizes disk usage of each FILE, recursively for directories.
and hoped I could use them together like this:
find . -type f | wc -l | du -hs
And I get a result, but how can I check if it's correct? Can you do this? Or is it some other command or combination of commands I should use?
Upvotes: 0
Views: 908
Reputation: 476699
Your last command is simply equivalent to du -hs
because du
does not read from stdin and thus does not care what you feed it.
Furthermore find . -type f | wc -l
does not give you the total file size, it simply counts the number of files in the current directory. That is because wc -l
looks at what you feed it, and count the number of lines, and find . -type f
simply writes a line (the name of the file) per file it finds in the directory (and its subdirectories).
But du -hs
should print a oneliner, something like:
$ du -hs
874M .
If you want to get the total size of a directory, you can simply feed it as argument, for instance:
$ du -hs /home/someuser/
172K /home/someuser/
Upvotes: 1