Upgrade yt-dlp from version `stable@2024.05.27` to `stable@2024.07.09`
[sunny256-utils.git] / dir-elems
blob79e29edf438b973aee306220ed4962c8f38dadb9
1 #!/usr/bin/env bash
3 #=======================================================================
4 # dir-elems
5 # File ID: 6a061bba-0014-11e5-8931-0d8802d731e4
7 # Create sorted list with number of directory elements in a directory
8 # tree. Useful to find directories with lots of files that need to be
9 # split up.
11 # Author: Øyvind A. Holm <sunny@sunbase.org>
12 # License: GNU General Public License version 2 or later.
13 #=======================================================================
15 progname=dir-elems
16 VERSION=0.3.0
18 ARGS="$(getopt -o "\
23 " -l "\
24 help,\
25 quiet,\
26 subtree,\
27 verbose,\
28 version,\
29 " -n "$progname" -- "$@")"
30 test "$?" = "0" || exit 1
31 eval set -- "$ARGS"
33 opt_help=0
34 opt_quiet=0
35 opt_subtree=0
36 opt_verbose=0
37 while :; do
38 case "$1" in
39 -h|--help) opt_help=1; shift ;;
40 -q|--quiet) opt_quiet=$(($opt_quiet + 1)); shift ;;
41 -s|--subtree) opt_subtree=1; shift ;;
42 -v|--verbose) opt_verbose=$(($opt_verbose + 1)); shift ;;
43 --version) echo $progname $VERSION; exit 0 ;;
44 --) shift; break ;;
45 *) echo $progname: Internal error >&2; exit 1 ;;
46 esac
47 done
48 opt_verbose=$(($opt_verbose - $opt_quiet))
50 if test "$opt_help" = "1"; then
51 test $opt_verbose -gt 0 && { echo; echo $progname $VERSION; }
52 cat <<END
54 Create sorted list with number of directory elements in a directory
55 tree. Useful to find directories with lots of files that need to be
56 split up.
58 Usage: $progname [options]
60 Options:
62 -h, --help
63 Show this help.
64 -q, --quiet
65 Be more quiet. Can be repeated to increase silence.
66 -s, --subtree
67 Count files in whole subtrees instead of single directories.
68 -v, --verbose
69 Increase level of verbosity. Can be repeated.
70 --version
71 Print version information.
73 END
74 exit 0
77 find "$@" -type d | while read f; do
79 cd "$f" && {
80 if test "$opt_subtree" = "1"; then
81 echo $(find | wc -l) $f
82 else
83 echo $(ls -a | wc -l) $f
87 done | sort -n