du skip symbolic links
This isn't du
resolving the symbolic links; it's your shell.
*
is a shell glob; it is expanded by the shell before running any command. Thus in effect, the command you're running is:
du -s /data/ghs/14 /data/ghsb/14 /data/hope/14 /data/rssf/14 /data/roper/14
If your shell is bash, you don't have a way to tell it not to expand symlinks. However you can use find
(GNU version) instead:
find /data -mindepth 2 -maxdepth 2 -type d -name 14 -exec du -s {} +
Make du
skip symbolic links:
du
isn't smart enough to not chase links. By default find
will skip symlinks. So creating an unholy alliance between find
, du
, and awk
, the proper dark magic incantation becomes:
find /home/somedirectory/ -exec du -s {} + | awk '{total = total + $1}END{print total}'
Produces:
145070492
To force the output to be human readable:
find /home/somedirectory/ -exec du -s {} + | awk '{total = total + $1}END{print (total / 1024 / 1024) "MB"}'
Produces:
138.35MB
What's going on here:
/home/somedirectory/ directory to search.
-exec du -s + run du -s over the results, producing bytes
awk '...' get the first token of every line and add them up,
dividing by 1024 twice to produce MB