Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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'?

share|improve this question

marked as duplicate by Gilles, warl0ck, jasonwryan, Mat, vonbrand Apr 24 '13 at 8:56

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

up vote 3 down vote accepted
while printf '%s ' "$(df -P / | awk 'NR==2 { print $(NF-1) }')"; do
    sleep 30
share|improve this answer
one-liner while printf '%s ' "$(df -P / | awk 'NR==2 { print $(NF-1) }')"; do sleep 30; done thank you – Radek Apr 23 '13 at 6: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 6:12

I'd prefer

watch -n 30 df

Man watch:

watch - execute a program periodically, showing output fullscreen

share|improve this answer
What is the advantage over my watch solution that at least only displays the root filesystem? – Anthon Apr 23 '13 at 5:51
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 5: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 6: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 6:39

you can use watch:

watch -n 30 -t df /

But that overwrites the existing output

share|improve this answer
You should read again what he wants. – Hauke Laging Apr 23 '13 at 5:35

Crude, but works:

while true; do printf "%s " $(df / | awk '/root/ {print $5}'); sleep 30; done
share|improve this answer
Shouldn't be the text = inside to loop? – Radek Apr 23 '13 at 5:40
But this would be every 30s + execution time of df, right? – Bernhard Apr 23 '13 at 5:42
Made it a one-liner... – jasonwryan Apr 23 '13 at 5:43
one-liner that can be run from a command line not from the script? If I copy&paste your code into command line and press enter it does nothing. – Radek Apr 23 '13 at 5:46
@Radek The root may be the problem. Adapt to your putput of df / or take my NR==2. – Hauke Laging Apr 23 '13 at 5:48

For bash:

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

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

share|improve this answer
@Anthon If I had just made it sleep 30 I might have been fast enough... – Hauke Laging Apr 23 '13 at 5: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 5: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 5: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 5:54

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