List the amount of space occupied by a file type in the terminal

5

I suspect that the PCs I use have many .RData files, used by the R program to save data sets. I want to do a cleanup on these files, but without going into directory by directory, from computer to computer. In addition, I use computers with at least 3 different operating systems: macOS, Ubuntu, and CentOS.

I already searched the internet and the command

find . -iname '*RData' -print0 | du -ch --files0-from=-

find the files you want, and calculate the space occupied by each of them. However, it only works on Ubuntu and CentOS. When I try to run macOS, I get the following message:

du: illegal option -- f
usage: du [-H | -L | -P] [-a | -s | -d depth] [-c] [-h | -k | -m | -g] [-x] 
[-I mask] [file ...]

What makes sense, because unlike du of Ubuntu and CentOS, du of macOS does not have the --files0-from flag.

How can I solve this problem in macOS? I suppose it's not through du , but is there any way to do this via terminal? I am using bash 4.4.12 (1) -release.

    
asked by anonymous 29.06.2017 / 15:40

2 answers

4

Solution with utilities find + du + awk :

$ find . -iname "*RData" | du | awk '{bytes+=$1} END{print bytes}'
    
29.06.2017 / 16:37
0
find . -name "*RData" -exec du -c {} +
    
04.08.2017 / 23:42