How to have one line updated, for example showing available disk space updated every second.
Within one line:
while true; do echo -ne "$(df | grep /dev/sda4)\\r"; sleep 1; done
how it works:
while true: start of endless loop
- -n: prevents line warp after outputting
- -e: allows backslash escape keys
- $(command): Runs the command and inserts the output
- \\r: the first backslash escapes the second, and \r stands for jumping to the beginning of the line
- sleep 1: pause for one second
done: end of endless loop
Within a script, you can write it into multiple lines:
echo -ne "$(df | grep /dev/sda4)\\r"