store diskspace value into variable

100 Views Asked by At

Using du command to get disk space, but only wanted the value, without the path. I am able to print using awk, but how to store only the value into variable?

du -sh $path | awk '{print $1}'
27G


du -sh $path
27G     $path
1

There are 1 best solutions below

1
ramsay On BEST ANSWER

You could use a variable to capture and store the output of du command:

disk_space=$(du -sh $path | awk '{print $1}')
echo "$disk_space"