How to view and clear logs in Linux server

Apache and other services generate logs, that can increase the size rapidly, and could take gigabytes of the hard drive.

View Log with tail

Let’s supose you want to view the log located at /usr/local/apache/logs/mylog.log
$tail /usr/local/apache/logs/mylog.log
It will show the last lines of the log, you can also tell the command to show more lines.

Clear Log

echo “” > /usr/local/apache/logs/mylog.log
It will replace the content of the file for an empty string.