• linux统计某个特定文件名的大小总和【原创】


    [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)为单位输出

    另一种更简单的方法,感谢superfly提供的方法

    [root@app01 b2c]# du -ch ./2019*
    672K    ./2019-05-29.log
    976K    ./2019-05-30.log
    848K    ./2019-05-31.log
    748K    ./2019-06-01.log
    792K    ./2019-06-02.log
    988K    ./2019-06-03.log
    1.1M    ./2019-06-04.log
    1.1M    ./2019-06-05.log
    1.2M    ./2019-06-06.log
    892K    ./2019-06-07.log
    1.4M    ./2019-06-08.log
    1004K    ./2019-06-09.log
    1.2M    ./2019-06-10.log
    1.2M    ./2019-06-11.log
    1.1M    ./2019-06-12.log
    1.1M    ./2019-06-13.log
    1012K    ./2019-06-14.log
    936K    ./2019-06-15.log
    904K    ./2019-06-16.log
    1.1M    ./2019-06-17.log
    1.1M    ./2019-06-18.log
    1.2M    ./2019-06-19.log
    1.1M    ./2019-06-20.log
    1.1M    ./2019-06-21.log
    972K    ./2019-06-22.log
    1.1M    ./2019-06-23.log
    1.2M    ./2019-06-24.log
    1.2M    ./2019-06-25.log
    1.2M    ./2019-06-26.log
    1.3M    ./2019-06-27.log
    31M    total

    转换的结果为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"G"

    转载请注明出处

  • 相关阅读:
    markdown 常用语法 (在macdown内使用正常)
    C# MessageBox常用用法
    C# 正则表达式匹配汉字
    C# 可视化读取文件、文件夹
    Xcode UUID查询
    Xcode 常用快捷键
    iOS __weak __strong WeakSelf StrongSelf
    iOS 图形图像动画 Core Animation
    iOS Runtime学习笔记
    iOS NSDate本地化
  • 原文地址:https://www.cnblogs.com/paul8339/p/9351675.html
Copyright © 2020-2023  润新知