Disk usage of files whose names match a regex, in Linux?

前端 未结 6 1615
耶瑟儿~
耶瑟儿~ 2020-12-23 21:19

So, in many situations I wanted a way to know how much of my disk space is used by what, so I know what to get rid of, convert to another format, store elsewhere (such as da

6条回答
  •  南方客
    南方客 (楼主)
    2020-12-23 21:47

    du is my favorite answer. If you have a fixed filesystem structure, you can use:

    du -hc *.bak
    

    If you need to add subdirs, just add:

    du -hc *.bak **/*.bak **/**/*.bak
    

    etc etc

    However, this isn't a very useful command, so using your find:

    TOTAL=0;for I in $(find . -name \*.bak); do  TOTAL=$((TOTAL+$(du $I | awk '{print $1}'))); done; echo $TOTAL
    

    That will echo the total size in bytes of all of the files you find.

    Hope that helps.

提交回复
热议问题