Search code examples
bashmacosdiskspace

Available diskspace on MacOsx


i want to write a script to download and restore a database on local machines. Is it possible to write a check in bash that just checks if there are more than 40gb of space on the device?

I tried it with df -h but the output doesnt seem useable. Maybe there is something iam missing with awk/sed?

Thanks for the help


Solution

  • df is a must. But the -h flag may be bad for this purpose.

    TARGET= # your target path here
    BLOCKS=$(df "$TARGET"| awk 'NR==2{print $4}')
    SIZE_FREE=$((BLOCKS * 1024))
    

    This gives the result you want. Result is $SIZE_FREE bytes.