Check folder size in Bash

前端 未结 8 804
情深已故
情深已故 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:50

    To just get the size of the directory, nothing more:

    du --max-depth=0 ./directory
    

    output looks like

    5234232       ./directory
    
    0 讨论(0)
  • 2020-12-12 09:57

    If it helps, You can also create an alias in your .bashrc or .bash_profile.

    function dsize()
    {
        dir=$(pwd)
        if [ "$1" != "" ]; then
                dir=$1
        fi
        echo $(du -hs $dir)
    }
    

    This prints the size of the current directory or the directory you have passed as an argument.

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