
在 Linux 中,我知道我可以使用
find ./ -size +1M
尋找大於 1M 的文件,但如何計算這些文件所需的總空間?
答案1
您可以-exec
對每個find
結果使用一個程式。
-exec utility [argument ...] {} +
與 相同
-exec
,除了 ```{}''is replaced with as many pathnames as possible for each invocation of utility. This behaviour is similar to that of
xargs(1)`。
運行du -c
結果中的磁碟使用總和(已使用的區塊數),如下所示:
find ./ -size +1M -exec du -c {} +
可以選擇添加-h
以獲得人類可讀的大小,或-k
1k 塊。-s
如果不同的find
表達式也傳回資料夾,則新增。
這要求不存在太多結果,因為它根據檔案名稱建立單一du
調用,如果該調用太長,它會將其分成具有單獨總計的單獨調用。