cd to the starting directory, then to count how many files and folders exist beneath,
find . -depth | wc -l
although in practice find . | wc -l works just as well leaving off -depth. Or to just count the number of files
find . -type f | wc -l
Note that on Linux, a better way to compare source and destination directories, might be to count the inodes used by either filesystem.
df -i
Exclude a hidden directory from the file count, e.g. .snapshots directory on a NetApp filer
#find ./ -type f \( ! -name “.snapshot” -prune \) -print | wc -l – Note: had real trouble with this!
New approach… :o(
ls -al | grep ^d | awk {‘print $9’} | grep -v “^\.” | while read eachdirectory; do
find ./ -depth | wc -l
done
Then add up numbers at the end.
Another way to count files in a large filesystem is to ask the backup software. If you use emc Networker, the following example may prove useful.
sudo mminfo -ot -q ‘client=mynas,level=full,savetime<7 days ago’ -r ‘name,nfiles’
name nfiles
/my-large-volume 894084