Check folder size in Bash

前端 未结 8 809
情深已故
情深已故 2020-12-12 08:50

I\'m trying to write a script that will calculate a directory size and if the size is less than 10GB, and greater then 2GB do some action. Where do I need to mention my fol

8条回答
  •  死守一世寂寞
    2020-12-12 09:34

    # 10GB
    SIZE="10"
    
    
    # check the current size
    CHECK="`du -hs /media/662499e1-b699-19ad-57b3-acb127aa5a2b/Aufnahmen`"
    CHECK=${CHECK%G*}
    echo "Current Foldersize: $CHECK GB"
    
    if (( $(echo "$CHECK > $SIZE" |bc -l) )); then
            echo "Folder is bigger than $SIZE GB"
    else
            echo "Folder is smaller than $SIZE GB"
    fi
    

提交回复
热议问题