Linuxでネストされたディレクトリのファイル数を数える方法は?

Linuxでネストされたディレクトリのファイル数を数える方法は?

特定のディレクトリツリーにどれだけのファイルがあるかに関する情報を抽出する必要があります。

  /.../testRoot/test1/test11/..../file1
  /.../testRoot/test1/test11/file2
  /.../testRoot/test1/test11/..../file3
  /.../testRoot/test1/test11/file4
.....................................
  /.../testRoot/test1/test1n/fileq
  /.../testRoot/test1/test1n/..../filew
  /.../testRoot/test1/test1n/filee
  /.../testRoot/test1/test1n/.../.../ .../filer

testRootにどのくらいのファイルがあるかを計算する方法は?

答え1

find /path/to/testRoot -type f | wc -l

答え2

中間bash4以上:

shopt -s nullglob globstar
i=0
for f in /path/to/testRoot/*/**; do
    [[ -f $f ]] && (( i++ ))
done
echo "$i"

関連情報