#!/usr/bin/env python3 """Per-child allocated size (GB) of each root. Prunes protected dirs before descent, skips symlinks, counts hardlinks once. Usage: tree_sizes.py ROOT [ROOT...]""" import os, sys EXCL = {"", "", ""} def size(p): if os.path.isfile(p): return os.lstat(p).st_blocks * 512 tot, seen = 0, set() for dp, dn, fn in os.walk(p, onerror=lambda e: None): dn[:] = [d for d in dn if d not in EXCL and not os.path.islink(os.path.join(dp, d))] for f in fn: try: st = os.lstat(os.path.join(dp, f)) except OSError: continue k = (st.st_dev, st.st_ino) if k in seen: continue seen.add(k) tot += st.st_blocks * 512 return tot for r in sys.argv[1:]: print("==", r) rows = [] for c in os.listdir(r): p = os.path.join(r, c) if os.path.islink(p): continue if c in EXCL: print(" EXCLUDED", c) continue rows.append((size(p), c)) for s, c in sorted(rows, reverse=True): if s >= 50e6: print(f" {s/1e9:6.2f} {c}")