1

I know I can get disk usage of the files/directories in a directory like this:

for file in $(ls); do du --hum --sum $file; done

That seems to break down if the files/directories have spaces in their names. So I tried this:

find . -maxdepth 1 -type d -print0 | xargs -0 du --hum --sum

That yields only this:

2.3G    .

Whereas there are 8 subdirectories in my directory.

jsf80238
  • 143

2 Answers2

1

You can also just apply the max-depth directive and take out --sum in your du invocation like so:

du --hum --max-depth=1

It will also display directories with spaces.

Here's example output demonstrating that directories with spaces will show up:

4.0K    ./regular_dir1
4.0K    ./regular_dir2
4.0K    ./dir with spaces
EWJ00
  • 381
0

Not as good as EWJ00:

find . -maxdepth 1 -type d -print0 | while read -d $'\0' file; do du --hum --sum "$file"; done
jsf80238
  • 143