Posted: . At: 2:03 PM. This was 11 years ago. Post ID: 5910
Page permalink. WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters.
These cookies expire two weeks after they are set.


How to watch a file in a terminal and see changes right away. Good for logfiles.


Here I am using the watch 'tail access.log' command to watch the access log file for the Apache web server. This will update every two seconds and show changes to the logfile when someone accesses the server.

Every 2.0s: tail access.log                                                                                           Tue Jul  2 10:26:04 2013
 
77.78.106.75 - - [30/Jun/2013:18:03:09 +1000] "HEAD / HTTP/1.0" 200 191 "-" "-"
127.0.0.1 - - [02/Jul/2013:10:17:31 +1000] "GET / HTTP/1.1" 200 980 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:22.0) Gecko/20100101 Firefox/22.0"
127.0.0.1 - - [02/Jul/2013:10:17:31 +1000] "GET /style.css HTTP/1.1" 200 816 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:22.0) Gecko/20100101 Firefox/22.0"
127.0.0.1 - - [02/Jul/2013:10:17:31 +1000] "GET /maps/back.png HTTP/1.1" 200 15197 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:22.0) Gecko/20100101 Firefox/22.0"
127.0.0.1 - - [02/Jul/2013:10:17:31 +1000] "GET /favicon.ico HTTP/1.1" 404 498 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:22.0) Gecko/20100101 Firefox/22.0"
127.0.0.1 - - [02/Jul/2013:10:19:45 +1000] "GET /maps/dmfaq66c.txt HTTP/1.1" 200 27655 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:22.0) Gecko/20100101 Firefox/22.0"
127.0.0.1 - - [02/Jul/2013:10:20:10 +1000] "GET /moodle/login/index.php HTTP/1.1" 200 909 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:22.0) Gecko/20100101 Firefox/22.0"

Using this command in an xterm you can watch in real time the programs that are running on the Linux system.

deep-thought ~ # watch "ps ax | tail -n 30"

This command will allow you to monitor the amount of hard disk space remaining on all mounted partitions.

deep-thought ~ # watch "df -Hla"

That could be very useful indeed.

Another way to monitor your system is watching running processes alone. This is done with the top command in a terminal. But the htop command is even more comprehensive.

Type sudo apt-get install htop to install this useful utility and then type htop to load it. This will show CPU load; memory usage and swap partition usage as well as a list of running processes that is updated in real time. Very useful utility to have running in an xterm to monitor your Linux system.


Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.