If you really want the total number of objects in your filesystems, use df -i
to count inodes. You won't get the breakdown between directories and plain files, but on the plus side it runs near-instantly. The total number of used inodes is something filesystems already track.
If you want to use one of the find
-based suggestions, don't just run it on /
. Use find -xdev
on a list of mount points generated by something like findmnt --list -v -U -t xfs,ext3,ext4,btrfs,vfat,ntfs -o TARGET
or something. That doesn't exclude bind mounts, though, so files under bind mounts will get counted twice. findmnt
is pretty cool.
Also, surely there's a straightforward way to list all your "disk" mounts without having to list explicit filesystem types, but I'm not sure exactly what.
As suggested by another answer, use find -printf . | wc -c
to avoid any possible problems counting funny characters in filenames. Use -not -type d
to count non-directory files. (You don't want to exclude your symlinks, do you?)