1

I have the following loop to view changing dir size:

while true; do du -hcs . ; sleep 2 ; clear ; done

What I'm not happy with is the waiting time between the clear and the actual output of du. The result is more or less a blinking number.

How can I modify this to simply write the new number over the old, with no black screen in between?

0

2 Answers 2

3
watch du -hcs .

From the man page:

watch runs command repeatedly, displaying its output (the first screenfull). This allows you to watch the program output change over time. By default, the program is run every 2 seconds; use -n or --interval to specify a different interval.

watch is smart: it only redraws the parts of the screen that have changed, avoiding the full screen clears that cause the blinking you see with clear.

Sign up to request clarification or add additional context in comments.

1 Comment

watch is Linux only. Not on BSD
0

I think that watch is the correct tool for what you are looking for, but

while true;do echo -n $(date +%Y%m%d%H%M%S) $(du -hcs ..|grep -v total);sleep 1;echo -e "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b";done

might be just the poor substitute that you are looking for.

If, however your shell is dash rather than bash, then use:

while true;do echo $(date +%Y%m%d%H%M%S) $(du -hcs ..|grep -v total)|tr -d '\n';sleep 1;echo $'\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b';done

6 Comments

I just ran this, but it doesn't overwrite the last line on my Ubuntu 16.04 system.
Is it possible that you are running inside of dash rather than bash? echo $0 to check.
It says "bash".
The command you added does the same, they print the output neatly on a new line each time.
Does the dash version work? or while true;do echo $(du -hcs ..|grep -v total)|tr -d '\n';sleep 1;echo $'\b\b\b\b\b\b\b\b\b\b';done ?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.