File Count

The purpose of this document is to show how to get an accurate count of the number of files in a directory.

In short, this is the best way:

find "/var/db/dropbox" -maxdepth 1 -mindepth 1 -name "*.zip" -printf . | wc -c

Here's a script that uses it:

#!/bin/bash # /opt/jgs/scripts/how-many-files.sh iso_date=$( date --rfc-3339=seconds --utc) dump_dir="/opt/dump_dir" # Count files in that directory num_files=$( find "${dump_dir}" -maxdepth 1 -mindepth 1 -name "*.zip" -printf . | wc -c ) echo "$num_files"

[Edit]