diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2016-11-25 19:59:33 +1300 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2016-11-25 19:59:33 +1300 |
commit | 3ec2a4181b016f7c56784db355ce1ed403547c58 (patch) | |
tree | 3d05be87f7bad9cc2c96034f71615caa67180b80 /bin | |
parent | Simplify cf(1df) and cfr(1df) (diff) | |
download | dotfiles-3ec2a4181b016f7c56784db355ce1ed403547c58.tar.gz dotfiles-3ec2a4181b016f7c56784db355ce1ed403547c58.zip |
Simplify cf(1df) with a find(1) command
This should also work for very large numbers of files
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/cf | 18 |
1 files changed, 6 insertions, 12 deletions
@@ -14,20 +14,14 @@ for dir in "${@:-.}" ; do continue fi - # Add files matching glob, shift them off if unexpanded (first and only - # entry doesn't exist) - set -- "$dir"/* - [ -e "$1" ] || shift - - # Add dot files, shift off the "." and ".." entries (sh(1) implementations - # seem to vary on whether they include these) - set -- "$dir"/.* "$@" - [ -e "$1" ] || shift - [ "$1" = "$dir"/. ] && shift - [ "$1" = "$dir"/.. ] && shift + # Count the files + count=$( + find "$dir" ! -path "$dir" -prune -exec printf %.sx {} + | + wc -c + ) # Print the count and the dirname - printf '%u\t%s\n' "$#" "$dir" + printf '%u\t%s\n' "$count" "$dir" done # Exit non-zero if a non-directory was given as an argument |