Differences between version 2 and previous revision of KnowledgeBase/Scripts/dunno.sh.
Other diffs: Previous Major Revision, Previous Author
Newer page: | version 2 | Last edited on Thursday, 22 April 2010 14:01:37 | by CyberLeo | Revert |
Older page: | version 1 | Last edited on Thursday, 22 April 2010 14:01:12 | by CyberLeo | Revert |
@@ -1,4 +1,6 @@
+...but it looks neat.
+
<code brush="bash">
#!/bin/sh
find . -print0 | xargs -0 stat --printf '%F\t%s\t%b\t%B\n' | awk -f /dev/fd/4 4<<'EOF'
function magnitude(count) {
version 2
...but it looks neat.
#!/bin/sh find . -print0 | xargs -0 stat --printf '%F\t%s\t%b\t%B\n' | awk -f /dev/fd/4 4<<'EOF' function magnitude(count) { count = count; mag = 0; while (count > 1024) { mag += 1; count /= 1024; } sym = syms[mag]; if (mag == 0) { return sprintf("%0.0f%s", count, sym); } else { if (count < 10) { return sprintf("%0.2f%s", count, sym); } else if (count < 100) { return sprintf("%0.1f%s", count, sym); } else { return sprintf("%0.0f%s", count, sym); } } } function commaize(count) { count = count out = "" while (count > 1000) { if (out == "") { out = sprintf("%03u", count % 1000) } else { out = sprintf("%03u,%s", count % 1000, out) } count /= 1000 } if (count > 0) { out = sprintf("%u,%s", count, out) } return out } function summary() { printf("\r%s bytes (%s on disk) in %s files; %s bytes (%s on disk) in %s dirs; %s bytes (%s on disk) total \033[K", magnitude(file_bytes), magnitude(file_blocks), commaize(file_count), magnitude(dir_bytes), magnitude(dir_blocks), commaize(dir_count), magnitude(file_bytes + dir_bytes), magnitude(file_blocks + dir_blocks)) } BEGIN { # Defines for prettymag syms[0] = "B" syms[1] = "K" syms[2] = "M" syms[3] = "G" syms[4] = "T" syms[5] = "P" # Counter initialization line_count=0 file_count=0 file_bytes=0 file_blocks=0 dir_count=0 dir_bytes=0 dir_blocks=0 other_count=0 other_bytes=0 other_blocks=0 } /^regular empty file/ { file_count++ } /^regular file/ { file_count++ file_bytes += $3 file_blocks += ( $4 * $5 ) } /^directory/ { dir_count++ dir_bytes += $2 dir_blocks += ( $3 * $4 ) } { line_count++ if ( line_count % 4096 == 0 ) { summary() } } END { summary() print } EOF