Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"tail -f" alternate which doesn't scroll the terminal window

Tags:

linux

bash

shell

I want to check a file at continuous intervals for contents which keep changing. "tail -f" doesn't suffice as the file doesn't grow in size.

I could use a simple while loop in bash to the same effect:

while [ 1 ]; do cat /proc/acpi/battery/BAT1/state ; sleep 10; done

It works, although it has the unwanted effect of scrolling my terminal window.

So now I'm wondering, is there a linux/shell command that would display the output of this file without scrolling the terminal?

like image 521
Jagtesh Chadha Avatar asked Jan 13 '11 06:01

Jagtesh Chadha


2 Answers

watch -n 10 cat /proc/acpi/battery/BAT1/state

You can add the -d flag if you want it to highlight the differences from one iteration to the next.

like image 73
SiegeX Avatar answered Nov 15 '22 04:11

SiegeX


watch is your friend. It uses curses so it won't scroll your terminal.

Usage: watch [-dhntv] [--differences[=cumulative]] [--help] [--interval=<n>] [--no-title] [--version] <command>
  -d, --differences[=cumulative]        highlight changes between updates
                (cumulative means highlighting is cumulative)
  -h, --help                            print a summary of the options
  -n, --interval=<seconds>              seconds to wait between updates
  -v, --version                         print the version number
  -t, --no-title                        turns off showing the header

So taking your example it'll be:

watch -n 10 cat /proc/acpi/battery/BAT1/state
like image 26
gabuzo Avatar answered Nov 15 '22 06:11

gabuzo