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

Asked

Viewed 74 times

5

I suspect that the Pcs I use have many files .RData, used by the R program to save data sets. I want to do a cleaning in these files, but without going into directory by directory, on computer by 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=-

finds the files I want, as well as calculating 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 ...]

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

How can I resolve this issue on macOS? I’m guessing it’s not through du, but is there any way to do this via terminal? I am using bash 4.4.12(1)-release.

2 answers

4


Solution with the utilities find + du + awk:

$ find . -iname "*RData" | du | awk '{bytes+=$1} END{print bytes}'
  • It seems to me that du no arguments, completely ignores the STDIN -- or will give a different result than expected (gives the current directory size).

0

find . -name "*RData" -exec du -c {} +

Browser other questions tagged

You are not signed in. Login or sign up in order to post.