When I use the cut command, everytime I get a different result which makes sense. So I wonder how to get the answer similar to this but consistent across different Ubuntu nodes?

ubuntu@ip:~/aws_script$ df -h / | grep '/dev'
/dev/xvda1       32G   21G  9.8G  68% /
ubuntu@ip:~/aws_script$ df -h / | grep '/dev' | cut -d' ' -f13
9.8G

I really don't care what command you would use if not cut as long as it gets the job done deterministically.

share|improve this question
1  
And why does the command you describe not suit your needs? Can you give an example where it does not work as intended? – Byte Commander Oct 19 '16 at 21:15
    
it doesn't work on block of spaces – Mona Jalal Oct 19 '16 at 21:17
up vote 2 down vote accepted

You want second line, fourth column. So use awk for that:

$ df -h / | awk 'NR==2{print $4}'                                                                                                     
41G
share|improve this answer

To get the available space on / with df, use:

df --output=avail -h / | grep -v ^Avail

How it works

--output=avail tells df to show just the available space.

grep -v ^Avail removes the header line.

share|improve this answer

awk is more powerfull than cut

df -h / |awk '/dev/{print $4}'

Modified as requested by Serg

share|improve this answer
    
Indeed awk is more powerful, but you're using grep here, which awk also can do. Just replace it with df -h / | awk '/dev/{print $4}' – Sergiy Kolodyazhnyy Oct 19 '16 at 21:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.