nicer file for doing file counts. way better output, simpler, also exhibits how...
[feisty_meow.git] / scripts / files / count_files.sh
1 #!/bin/bash
2
3
4 # make sure they gave us some arguments.
5 if [ -z "$1" ]; then
6 #hmmm: could use the count notation instead of sloppy empty check.
7   # reset first arg to be '*' to do any directories here.
8 #echo changing args to use all subdirs in current dir.
9   set -- $(find . -maxdepth 1 -mindepth 1 -type d) "${@:2}"
10 #echo "arg 1 is now '$1'"
11 fi
12
13 # run through all the parameters provided and find any
14 # directories under them (or probably barf if they're not
15 # dirs).
16 for i in "${@}" ; do
17   # print the count of files followed by directory name,
18   # with leading zeros to allow sorting, which get
19   # redigested as spaces before showing the list.
20   printf "%06d -- %s\n" $(find "$i" -type f | wc -l) "$i"
21 done |
22 # provide sorted output based on how many files exist
23 # in each directory.
24   sort -r |
25 # eat the zeroes but keep the tabular look.  this simple
26 # sed code will eat zeroes in names also.  oops.
27   sed -e 's/0/ /g'
28