Sometimes (especially when you are an administrator) there may be a need, to see the content of a specific file in a real time – for example log file.
You could open file, go down to see last entries, close file and then repeat the whole process to see if there have been done some changes but for sure you will say, that this method is annoying and not so effective. I will show you how to see files content in a real time (without the need to reopen them, to see if changes occured). Two commands for today – tail and grep.
Open terminal and log into one of your web servers:
ssh -l root 10.1.0.186
Now let’s go to logs directory:
We are curious about the ammount of request sent to our server, so we should browse file called access.log:
tail -f access.log
You should see now the real time preview of access.log. The speed of appearing new lines is connected with number of request your server is handling right now. To quit live preview press:
CTRL + C
tail -f access.log | grep ".js"
Isn’t that awesome? Please notice that “the magic” is done by the “-f” parameter after tail command – it means “follow”.