0

How can I make a output like htop?

That is to say that the information is continually reinforced. I had thought of something like this but I don't think it's completely right and I'm sure there are better ways to do it.

while true ; do
   ls
   sleep 3
   clear
done

I would like to do it with bash but I am open to other proposals.

Cyrus
  • 84,225
  • 14
  • 89
  • 153

2 Answers2

2

You can use watch utility for such a task:

$ watch -n 10 script.sh

the above command will execute the script.sh every 10 seconds you can change it through n option.

or for your command you can do it like this:

$ watch -n 3 ls
ROOT
  • 11,363
  • 5
  • 30
  • 45
1

htop uses ncurses (https://www.gnu.org/software/ncurses/) which is a C library developed for making terminal interfaces.

If you'd like to stick with plain old bash, you could try echoing some output, then echoing backspace \b characters and spaces to overwrite it, followed by echoing new output again. You can also make use of system tools like tput to get terminal dimensions and things of that nature. I would suggest not going the bash route however.

tmathmeyer
  • 53
  • 1
  • 4