From 082d1ce6c2d109912119a581086f36c9eaa368b6 Mon Sep 17 00:00:00 2001 From: Chris Koeritz Date: Sun, 4 Sep 2016 17:37:02 -0400 Subject: [PATCH] nicer file for doing file counts. way better output, simpler, also exhibits how to change cmd line args to bash --- scripts/files/count_files.sh | 28 +++++++++++++++++++++++++ scripts/files/count_files_in_subdirs.sh | 9 -------- 2 files changed, 28 insertions(+), 9 deletions(-) create mode 100644 scripts/files/count_files.sh delete mode 100644 scripts/files/count_files_in_subdirs.sh diff --git a/scripts/files/count_files.sh b/scripts/files/count_files.sh new file mode 100644 index 00000000..b869b05c --- /dev/null +++ b/scripts/files/count_files.sh @@ -0,0 +1,28 @@ +#!/bin/bash + + +# make sure they gave us some arguments. +if [ -z "$1" ]; then +#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. + set -- $(find . -maxdepth 1 -mindepth 1 -type d) "${@:2}" +#echo "arg 1 is now '$1'" +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 + # 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" +done | +# 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' + diff --git a/scripts/files/count_files_in_subdirs.sh b/scripts/files/count_files_in_subdirs.sh deleted file mode 100644 index 7814ca01..00000000 --- a/scripts/files/count_files_in_subdirs.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash -dirs=($*) -if [ -z "$dirs" ]; then dirs=($(find . -mindepth 1 -maxdepth 1 -type d ) ); fi -#echo dirs are ${dirs[*]} -for i in "${dirs[@]}"; do - echo -n $(ls -1 $i | wc -l) - echo -e "\t\t$i" -done - -- 2.34.1