Forums

How to check the free disk space volume from bash?

I have a bash script to backup my files.

  zip arc/arc_${now}.zip my_files

added to daily tasks.

How to check for the free disk space in this script?

Hi there, perhaps you may use the du command to figure out how much space has been used up by your zip file?

Hi!

No, I'm looking for command to check the free desk space, to write something like

if FREE_DISK_SPACE < 100 MB
    then DELETE_OLD_BACKUP

We have a help page on disk quota: https://help.pythonanywhere.com/pages/DiskQuota/ .

You can slightly change the command which is used there to get the total of disk usage for your $HOME and /tmp directories:

du -cs /tmp ~ | awk '/total/ {print $1}'

Yes, this command print out the total space volume. And how to make the IF statements (to skip the zip command if disk free space is a less then const)?

You could try using Python's subprocess module to call it (I'd recommend subprocess.check_output) and then parse the results -- then you can do your if statement and use suprocess again to call the zip command.