linux,

Status Monitoring - Statusbar

agowa338 agowa338 Oct 19, 2015 · 1 min read
Share this

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

  • echo:
    • -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:

while true
do
     echo -ne "$(df | grep /dev/sda4)\\r"
     sleep 1
done

agowa338
Written by agowa338