I want to list the size of directories under a given root (using du -hs
) . The issue is that where the directory names have spaces the du
command is getting each word of the name as a whole directory name.
I tried to fix this by quoting the output through xargs
but the output is the same.
#!/bin/bash
root="$1"
echo "Searching in $root"
for d in $(find $root -maxdepth 1 -type d | xargs -i echo "'{}'")
do
#
# the root directory can take a long time so let's skip it
#
if [ "$d" != "$root" ]
then
echo "Looking at directory $d"
echo $(du -hs "$d")
fi
done