Skip to content
gfxmonk edited this page Dec 18, 2014 · 11 revisions

Examples

List the total size of all root directories (ignoring mounts)

ls -1 / | piep 'root=set(pp) | pp = sh("mount").splitlines() | p.split() | p[2] | p[1:] | \
  "/" not in p | bool | root.difference(set(pp)) | "/"+p | \
  sh("du","-hs", *list(pp), stderr=open(os.devnull), stdout=sys.stdout)'

Explanation:

  • root=set(pp) : convert input (ls -1 /) into into a set, for later
  • | pp = sh("mount").splitlines() : run mount, and save its lines as the new pp
  • | p.split() | p[2] | p[1:] | "/" not in p : grab the path component, trim off the leading slash and remove any paths that have more than one slash
  • | bool : filter out the empty result
  • | root.difference(set(pp)) : set pp to the difference of the stored root variable and the current pp value
  • | "/"+p : add back leading slash
  • | sh("du","-hs", *pp, stderr=open(os.devnull), stdout=sys.stdout) : run du -hs on all paths. Print directly to stdout, and ignore stderr
Clone this wiki locally