View the number of files in each subfolder within the specified folder in Linux
- 2021-01-02 22:07:13
- OfStack
count script
#!/bin/sh
numOfArgs=$#
if [ $numOfArgs -ne 1 ]; then
echo -e "Usage: \nbash $0 dirForCount"
exit -1
fi
# args
ROOTDIR=$1
# core part
find $ROOTDIR -maxdepth 1 -type d | sort | while read dir; do
count=$(find "$dir" -type f | wc -l)
echo "$dir: $count"
done
perform
[
$ bash count.sh benchmark
benchmark: 2317
benchmark/0: 20
benchmark/1: 891
benchmark/2: 65
benchmark/3: 13
benchmark/4: 1328
conclusion