tr -cd '[:space:]' < my_file | wc -m Would work. But with GNU tr, that would only work in single byte per character locales (typically, not in UTF-8 ones) or with ASCII only input in UTF-8 locales.
Without the quotes around [:space:], you'd get an error message in csh, tcsh or zsh (unless the condition below is met) and in most shells, that would fail if there was a file called :, s, p, a, c or e in the current directory as [:space:] is a shell glob.
Also note that wc doesn't count characters by default (it's bytes, words and newlines only when not given any option).
With GNU awk you can use:
awk -v RS='[[:space:]]' 'END{print NR}' Example:
$ printf '\0\u2006\t\r\n' | awk -v RS='[[:space:]]' 'END{print NR}' 4 (for the U+2006 SIX-PER-EM SPACE, TAB, CR and NL characters which are all classified as whitespace in my locale).