Short command to find total size of files matching a wild card

前端 未结 3 2079
自闭症患者
自闭症患者 2021-02-18 14:04

I could envision a simple shell script that would accomplish what I want by just iterating through a list of files in a directory and summing the individual size but was wonderi

相关标签:
3条回答
  • 2021-02-18 14:37

    You can use this function :

    dir () { ls -FaGl "${@}" | awk '{ last_size += $4; print }; END { print last_size }'; }
    

    also you can use this command this is shorter and give you better result!

    find YOUR_PATH -type f -name '*.jpg' -exec du -ch {} +
    
    0 讨论(0)
  • 2021-02-18 14:42

    Try du to summarize disk usage:

    du -csh *.jpg
    

    Output (for example):

    8.0K sane-logo.jpg
    16K sane-umax-advanced.jpg
    28K sane-umax-histogram.jpg
    24K sane-umax.jpg
    16K sane-umax-standard.jpg
    4.0K sane-umax-text2.jpg
    4.0K sane-umax-text4.jpg
    4.0K sane-umax-text.jpg
    104K total
    

    du does not summarize the size of the files but summarizes the size of the used blocks in the file system. If a file has a size of 13K and the file system uses a block size of 4K, then 16K is shown for this file.

    0 讨论(0)
  • 2021-02-18 14:48

    For don't show files list, and just show total size, use this:

    du -ch *.php.* | grep total
    

    Output:

    196M    total
    
    0 讨论(0)
提交回复
热议问题