Here is a version that passes Directory[]
to df so you know how much space there is in MathematicasMathematica's current working directory.
I have tried it on linuxLinux but I see no reason it shouldn't work on OSX and other unixy systems that have df.
Options[freeSpace] = {"Path" :> Directory[], "Property" -> 4};
freeSpace[OptionsPattern[]] :=
Module[{out =
ReadList["!df '" <> ToString[OptionValue["Path"]] <> "'"
,Word
,RecordLists -> True]
,i ,val},
val = out[[-1, OptionValue["Property"]]];
Quiet[Check[
FromDigits[val],
val, FromDigits::nlst
], FromDigits::nlst]
]
You can do similarly with @WReach's solution, which would be better since it will work on all systems.
JavaBlock[JavaNew["java.io.File", Directory[]]@getFreeSpace[]]
You can also check how much free space is on another disk, say you store your stuff elsewhere:
freeSpace[] (* 8898584 *)
freeSpace["Path"-> "/tmp"] (* 20958736 *)
You can also extract other information that df gives:
freeSpace["Path" -> "/tmp", "Property" -> 1] (* "/dev/sda5" *)
The different properties are:
1 2 3 4 5 6
Filesystem Size Used Avail Use% Mounted on