Linux show last (n) rows of file
If you have ssh access to a server you can have a live view on whats happening by displaying the last lines of the error or access log. Here is it and how is explained below.
cd /logs tail -n 10 -f error_log | cut -b 1-200
- You have to navigate to where your error or access logs are, change it to yours
- execute your version of the command above, no harm can be done
- stop by key combination ‘Ctrl + c’
Taking the command apart
- tail – the command running
- -n 10 – show the last 10 lines
- error_log – this is the filename in my case, change it to yours
- -f – keep monitoring (live view)
- | cut – b 1-200 – show the first 200 characters of each line
watch -n 20 tail -n 8 error_log
If you prepend the command with a watch command you can control the time the view refreshes. This can make it less intensive.
- watch -n 10 – This will make it refresh every 10 seconds
Doing this with WordPress
WordPress can have it’s own error logging, you can monitor this with the tail command. To setup WordPress error logging read this
Doing this to debug your own code
You can add your errors to the WordPress debug log and get control over the quality of your code: debug your own custom code