From b1f2a33eb394981b063b80beb22425413ca1f47d Mon Sep 17 00:00:00 2001 From: Michiel Borkent Date: Wed, 27 Nov 2019 22:55:21 +0100 Subject: [PATCH] Add gallery example: dir-size --- README.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/README.md b/README.md index 192cf74d..7f52bcaf 100644 --- a/README.md +++ b/README.md @@ -514,6 +514,28 @@ welcome! find . | grep conflict | bb -i '(doseq [f *in*] (.delete (io/file f)))' ``` +### Calculate aggregate size of directory + +``` clojure +#!/usr/bin/env bb + +(as-> (io/file (or (first *command-line-args*) ".")) $ + (file-seq $) + (map #(.length %) $) + (reduce + $) + (/ $ (* 1024 1024)) + (println (str (int $) "M"))) +``` + +``` shellsession +$ dir-size +130M + +$ dir-size ~/Dropbox/bin +233M +``` + + ### Shuffle the lines of a file ``` shellsession