diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2016-09-02 00:20:12 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2016-09-02 00:31:25 +1200 |
commit | b59b96c291a5ddd02a58c9e91627cca5aadc6138 (patch) | |
tree | 9fe50993739a1a64a62846fe022046c867294ed2 /bin | |
parent | Add tot(1df) (diff) | |
download | dotfiles-b59b96c291a5ddd02a58c9e91627cca5aadc6138.tar.gz dotfiles-b59b96c291a5ddd02a58c9e91627cca5aadc6138.zip |
Reimplement cfr(1df) using cf(1df)
Resolves issue; not as fast as non-portable printf hack, but good
enough. Also properly excludes root from the count.
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/cfr | 12 |
1 files changed, 7 insertions, 5 deletions
@@ -1,6 +1,8 @@ #!/bin/sh -# Count files recursively with find(1); this includes the given directories -# themselves and their subdirectories as entries, and correctly handles files -# with newlines in their names. It's also all POSIX ... but on big directories, -# it's *slow*. -find "${@:-.}" -exec printf %.sx {} \; | wc -c +# Count all descendants of given directories +for dir in "${@:-.}" ; do + tot=$(find "$dir" -type d \ + -exec sh -c 'cd -- "$1" && cf' _ {} \; | + cut -f1 | tot) + printf '%u\t%s\n' "$tot" "$dir" +done |