Skip to content

Instantly share code, notes, and snippets.

@cschaba
Created February 8, 2013 16:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save cschaba/4740323 to your computer and use it in GitHub Desktop.
Save cschaba/4740323 to your computer and use it in GitHub Desktop.
PHP: parse output of "df -k"
$data = <<<EOF
Filesystem 1K-blocks Used Available Use% Mounted on
ubi0_0 143180 89740 53440 63% /
tmpfs 64 0 64 0% /dev
tmpfs 143124 76 143048 0% /tmp
tmpfs 4096 912 3184 22% /var
tmpfs 64 0 64 0% /mnt
ubi1_0 468256 12144 456112 3% /opt/data/settings
EOF;
print_r(array_map(function($line){
$elements=preg_split('/\s+/',$line);
return(array(
'filesystem' => $elements[0],
'1k-blocks' => $elements[1],
'used' => $elements[2],
'available' => $elements[3],
'use%' => $elements[4],
'mounted_on' => $elements[5]
));
},explode("\n",$data)));
@gsouf
Copy link

gsouf commented Dec 3, 2013

Thanks, you saved me a couple of minutes :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment