How do I search through my log files for errors? (Linux)

You can use several options to streamline the viewing of large text files, such as /var/log/messages. Some of these options are described in the article below.

# head
The head command will print the first 10 lines of a file to the screen. This can be coupled with the options "-n " to display a larger number of lines. So for instance,
# head -n 40
would display the top 40 lines of a text file.

# tail
Much like #head, the tail command will display the last 10 lines of a text file. This can also be coupled with the option "-n " to display a larger number of lines. "-f",output appended data as the file grows.

tail -f /path/to/log for example tail -f /var/cron/log  shows the cron log file.

# cat
Cat will print the entire contents of a file to the screen.

You can also add a '| grep' to the end of any of these commands to search for a specific word. For instance,

# cat testing.txt | grep error

would only report the lines containing the word 'error'. Note that this is case-sensitive.

  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

How do I bind my additional IPs?

These instructions are for CentOS / Fedora specifically.By default, we only binds your first...

How do I run a traceroute?

Both Windows and Linux have the ability of diagnosing the health of a connection between a source...

How do I schedule FSCK to run automatically?

Using cron to schedule an FSCKBy default, a fsck is forced after 30 reboots or 180 days.To avoid...

Why is cPanel/WHM not loading?

There are two main reasons why cPanel/WHM isn't loading that we've seen.Brand New ServerIf you...

How to install cPanel on CentOS

Installation Notes A CentOS or Red Hat server that is going to have cPanel installed needs a...