aboutsummaryrefslogtreecommitdiff
path: root/bin/cf
blob: 4a4c7f7fa15dbd893edf5e7581c03e0b027f06e0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/bin/sh
# Count entries in a given set of directories
self=cf

# Iterate over remaining non-option arguments (directories); default to current
# directory if none given
for dir in "${@:-.}" ; do

    # Warn if a non-directory was given, flag errors, but continue
    if ! [ -d "$dir" ] ; then
        printf >&2 '%s: %s: not a directory\n' \
            "$self" "$dir"
        ex=1
        continue
    fi

    # 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' "$count" "$dir"
done

# Exit non-zero if a non-directory was given as an argument
exit "${ex:-0}"