I have a variable called $driveusage that contains the following block of text:
Filesystem Type Size Used Avail Use% Mounted on
rootfs rootfs 111G 8.7G 96G 9% /
/dev/sda1 ext3 111G 8.7G 96G 9% /
devtmpfs devtmpfs 59M 0 59M 0% /dev
tmpfs tmpfs 61M 0 61M 0% /dev/shm
tmpfs tmpfs 61M 264K 60M 1% /run
tmpfs tmpfs 61M 0 61M 0% /sys/fs/cgroup
tmpfs tmpfs 61M 16K 61M 1% /tmp
I need to extract data from the rootfs line only, into separate variables (i.e. $drivesize, $driveused, $drivefree, not an array), just the size, used and avail numbers, and just the numbers only (including the decimal).
Keep in mind that the used value, once it goes over 9.9G, will appear as 10G (with no decimal point) and same when avail drops below 10G will appear as 9.9G.
I’ve tried every combination of preg_replace() but I’m just not good with those complex expressions. 🙁
Any help you could provide would be greatly appreciated 🙂
Here’s what I got:
df -H /gets human-readable info about your disk,tail -1gets the last line of that (the important figures, andtr -s ' ' | cut -d ' ' -f 2,3,4gets the second, third, and fourth entries (“size”, “used”, and “avail”) in that row.