X-Git-Url: https://feistymeow.org/gitweb/?a=blobdiff_plain;f=scripts%2Ffiles%2Fcount_files.sh;h=847fb68e1d30ea25bce9623dbfda0ee3642f8c85;hb=17c68404134083f61ef0884ddd4ef4df4fdfa992;hp=b869b05cf346420bef93cf6d595ed77a0864ca37;hpb=082d1ce6c2d109912119a581086f36c9eaa368b6;p=feisty_meow.git diff --git a/scripts/files/count_files.sh b/scripts/files/count_files.sh index b869b05c..847fb68e 100644 --- a/scripts/files/count_files.sh +++ b/scripts/files/count_files.sh @@ -1,28 +1,34 @@ #!/bin/bash +# counts the number of files in a set of directories. +# if no directories are provided, uses the current working directory. -# make sure they gave us some arguments. -if [ -z "$1" ]; then +# make sure they gave us some arguments, or go with our default of the current dir. #hmmm: could use the count notation instead of sloppy empty check. - # reset first arg to be '*' to do any directories here. -#echo changing args to use all subdirs in current dir. +if [ -z "$1" ]; then + # reset the arguments list to scan any directories found in cwd. + SAVEIFS="$IFS" + IFS=$(echo -en "\n\b") set -- $(find . -maxdepth 1 -mindepth 1 -type d) "${@:2}" -#echo "arg 1 is now '$1'" + IFS="$SAVEIFS" fi -# run through all the parameters provided and find any -# directories under them (or probably barf if they're not -# dirs). -for i in "${@}" ; do +# run through all the parameters provided and find any directories under them +# (or probably barf if they're not dirs). +#hmmm: really? "barf" is an implementation strategy now? +for countfilesname in "${@}" ; do +# echo "arg is: '$countfilesname'" # print the count of files followed by directory name, # with leading zeros to allow sorting, which get # redigested as spaces before showing the list. - printf "%06d -- %s\n" $(find "$i" -type f | wc -l) "$i" + printf "%06d -- %s\n" $(find "$countfilesname" -type f | wc -l) "$countfilesname" done | -# provide sorted output based on how many files exist -# in each directory. + # provide sorted output based on how many files exist + # in each directory. sort -r | -# eat the zeroes but keep the tabular look. this simple -# sed code will eat zeroes in names also. oops. - sed -e 's/0/ /g' + # eat the zeroes but keep the tabular look (i.e. replace each leading zero + # with a space). had to do it as cases, since this seems like context- + # sensitive matching, which sed will not do, i think). + sed -e 's/^000000/ 0/' -e 's/^00000/ /' -e 's/^0000/ /' \ + -e 's/^000/ /' -e 's/^00/ /' -e 's/^0/ /'