9

All I want to see is the % after I issue df / every 30s but on the same line just after the previous number.

So the final output would be 86% 86% 86% 87% 87% ......

Could it be one line code? Or multiple line 'program'?

Radek
  • 2,943
  • 18
  • 39
  • 52

5 Answers5

24

I'd prefer

watch -n 30 df

Man watch:

watch - execute a program periodically, showing output fullscreen

superuser0
  • 1,690
  • 1
  • 11
  • 20
  • What is the advantage over my watch solution that at least only displays the root filesystem? – Anthon Apr 23 '13 at 05:51
  • 3
    Upvoted because I didn't know that watch existed. But I don't think your solution can deliver what I asked for. – Radek Apr 23 '13 at 05:53
  • @Radek I just asked because it seemed a copy of my answer coming in 9 minutes later as well showing even more that you did not want. – Anthon Apr 23 '13 at 06:19
  • Your answer wasn't there when I started to write mine, I also edited my post a bit later and maybe it displays that time as the posting time. I certainly don't copy answers. – superuser0 Apr 23 '13 at 06:39
6
while printf '%s ' "$(df -P / | awk 'NR==2 { print $(NF-1) }')"; do
    sleep 30
done
echo
Chris Down
  • 122,090
  • 24
  • 265
  • 262
  • 1
    one-liner `while printf '%s ' "$(df -P / | awk 'NR==2 { print $(NF-1) }')"; do sleep 30; done` thank you – Radek Apr 23 '13 at 06:08
  • What would be syntax for alias? I cannot make it work... alias df2='while printf \'%s \' "$(df -P / | awk \'NR==2 { print $(NF-1) }\')"; do sleep 30; done' is not correct – Radek Apr 23 '13 at 06:12
4

you can use watch:

watch -n 30 -t df /

But that overwrites the existing output

Anthon
  • 78,313
  • 42
  • 165
  • 222
2

Crude, but works:

while true; do printf "%s " $(df / | awk '/root/ {print $5}'); sleep 30; done
jasonwryan
  • 71,734
  • 34
  • 193
  • 226
1

For bash:

i=1
outputs_per_line=10
frequency=30
while true; do
  echo -n "$(df / | awk 'NR==2 {print $5}') "
  if [ $((i%outputs_per_line)) -eq 0 ]; then
    echo
  fi
  ((i++))
  sleep "$frequency"
done

The line break after $outputs_per_line numbers shall prevent a console line break within the output.

Hauke Laging
  • 88,146
  • 18
  • 125
  • 174
  • @Anthon If I had just made it `sleep 30` I might have been fast enough... – Hauke Laging Apr 23 '13 at 05:45
  • Interesting how your edit doesn't show up as a revision. I will delete my comment, now it seems inappropriate – Anthon Apr 23 '13 at 05:47
  • @Anthon I assume there's a threshold of a few seconds or minutes below which revisioning is considered not useful. – Hauke Laging Apr 23 '13 at 05:49
  • That is probably it. I am not sure if your change was there before I commented. I would expect you were first, and that a comment would reduce the grace period for editing (to prevent these kind of discussions). I will browse meta (SO) to see if there is something. – Anthon Apr 23 '13 at 05:54