from subprocess import * lines = getoutput('df -h | grep "^/dev/"').split("\n") spaces = [] for line in lines: split_line = line.split() spaces.append(split_line[3]) print(spaces) total = 0 for space in spaces: if "T" in space: total += 1000 * float(space[:-1]) elif "G" in space: total += float(space[:-1]) else: print("Unknown space: ", space) print("Total Space: ", str(total) + "G")