Consider a directory structure as follows:
$ ls -sR1
Then to get a list of all files which do not match
*.pdf, we can do
$ find . -type f \( ! -name '*.pdf' \)
whose expansion to also not match, say,
*.jpg is rather obvious. Then use
du as follows:
$ du -c $(find . -type f \( ! -name '*.pdf' \))
where you might want to throw in a
-b to get the apparent size in bytes rather than disk usage.
-c gives out the grand total.
The limitations of this approach are:
- It won’t work if your directory tree is very large, because
- Because it scans the tree twice (
- Because it feeds the output of
du via the command line and is thus bounded by the maximum allowed size for that.
- It will (in this naive approach) only match files based on their names, not their content.
You can overcome 1. by using
find to execute
du on each individual file and then use
awk or something similar to add it all up. 2. might be solved by more intriguing checks in
find, possibly based on the output of
file for each file and matching it against a positive or negative list.