将磁盘空间值存入变量。

huangapple go评论94阅读模式
英文:

store diskspace value into variable

问题

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

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

得分: 0

你可以使用一个变量来捕获并存储du命令的输出:

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

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"

huangapple
  • 本文由 发表于 2023年5月11日 10:58:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/76223865.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定