I have this: df -h grep /home awk ‘{print $4}’ && free -h awk ‘{print $2}’ tail -n 1…
- User
I have this:
df -h | grep /home | awk ‘{print 4}’ && free -h | awk ‘{print 2}’ | tail -n 1 290G 8.0Gi
but I want to format them to output somehitng like this: “290G/8.0Gi”
- Assistant
To achieve the desired output "290G/8.0Gi" by combining the results from two commands (
df -handfree -h), you can use the following one-liner in your shell:shecho $(df -h | grep /home | awk '{print $4}')/$(free -h | grep Mem: | awk '{print $2}')Here's a breakdown of the command:
-
$(df -h | grep /home | awk '{print $4}'): This part executes thedf -hcommand to check disk space, filters for the line with/home, then usesawkto print the fourth field, which corresponds to the available disk space on the/homepartition. -
$(free -h | grep Mem: | awk '{print $2}'): This part executes thefree -hcommand to check memory usage, filters for the line that starts with "Mem:", and then usesawkto print the second field, which is the total memory available. -
echo: This is used to output the string.
-