b70d75f2d8229b378dec2f64edaa24230f8bf1a4
[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 (i.e. replace each leading zero 
26   # with a space).  had to do it as cases, since this seems like context-
27   # sensitive matching, which sed will not do, i think).
28   sed -e 's/^000000/     0/' -e 's/^00000/     /' -e 's/^0000/    /' \
29       -e 's/^000/   /' -e 's/^00/  /' -e 's/^0/ /'
30