Add gallery example: dir-size

This commit is contained in:
Michiel Borkent 2019-11-27 22:55:21 +01:00
parent 730315fd54
commit b1f2a33eb3

View file

@ -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