I suggest something like: find . -regex '.*\.bak' -print0 | du --files0-from=- -ch | tail -1
Some notes:
- The
-print0
option forfind
and--files0-from
fordu
are there to avoid issues with whitespace in file names - The regular expression is matched against the whole path, e.g.
./dir1/subdir2/file.bak
, not justfile.bak
, so if you modify it, take that into account - I used
h
flag for du to produce a “human-readable” format but if you want to parse the output, you may be better off withk
(always use kilobytes) - If you remove the
tail
command, you will additionally see the sizes of particular files and directories
Sidenote: a nice GUI tool for finding out who ate your disk space is FileLight. It doesn’t do regexes, but is very handy for finding big directories or files clogging your disk.