BASIC · lesson 26 of 30 · Tools for the NASRead df
Run df -P -k for a folder, cut its second line and turn blocks into GiB.
26-free-space.yab Download 26-free-space.yab
rem Free space of the volume that holds a folder
folder$ = peek$("argument")
if folder$ = "" folder$ = "."
dim line$(1), field$(1)
n = token(system$("df -P -k '" + folder$ + "'"), line$(), chr$(10))
if n < 2 then
print "df knows nothing about ", folder$
exit 1
endif
m = token(line$(2), field$(), " ")
total = val(field$(2)) / 1024 / 1024
free = val(field$(4)) / 1024 / 1024
print str$(free, "%.1f"), " GiB of ", str$(total, "%.1f"), " GiB are free"
if free / total < 0.1 print "Less than 10 percent is left"
Terminal
$ yabasic 26-free-space.yab .
1035.3 GiB of 1327.1 GiB are freeThe numbers or the date differ on your NAS.
Exercise
Take a limit in percent as the second argument.