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
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"