[hch@EAISRVBJ2 log]$find ./ -name "test_chs_00*"|xargs du -ck|grep total|awk ‘BEGIN{sum=0}{sum+=$1}END{print sum}‘
315590856
参数说明
-c或--total 除了显示个别目录或文件的大小外,同时也显示所有目录或文件的总和。
-k或--kilobytes 以KB(1024bytes)为单位输出
转换的结果为KB,将其转换为G。用bc计算
[hch@EAISRVBJ2 log]$ bc bc 1.06.95 Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc. This is free software with ABSOLUTELY NO WARRANTY. For details type `warranty‘. 315590856/1024/1024 300 quit
转换结果为300G
如果没有安装bc,用let计算
[hch@EAISRVBJ2 log]$var1=`find ./ -name "EAIObjMgr_chs_00*"|xargs du -ck|grep total|awk ‘BEGIN{sum=0}{sum+=$1}END{print sum}‘` [hch@EAISRVBJ2 log]$ let "var=$var1/1024/1024" [hch@EAISRVBJ2 log]$ echo $var 299
写在一起执行如下:
var1=`find ./ -name "EAIObjMgr_chs_00*"|xargs du -ck|grep total|awk ‘BEGIN{sum=0}{sum+=$1}END{print sum}‘` && let "var=$var1/1024/1024" && echo $var
转载请注明出处
原文:https://www.cnblogs.com/paul8339/p/9351675.html