Question
How do I truncate a log file?
Answer
Warning: Please make sure you discuss this with a qualified system administrator before performing the following actions as they may result in data loss
Sometimes log files get rather large, and rather than back them up; you may want to truncate the file to a smaller size. Below is how you would do this.
The command you would want to run is the truncate command. The simplest way to do this is the following:
- Log in to the server via SSH or WHM's Terminal as the
rootuser -
Run the following command:
# truncate -s 100M FILE_NAME
Note: You need to replace "FILE_NAME" with the path and file name of the log you wish to truncate.
The command does the following:
Truncates the file to the most recent 100 Megabytes of data (retains the newest data and removes all older data in the file above the 100M in size).
For more information on truncate, please refer to the following documentation for truncate built into your operating system:
# man truncate
Also, you may want to truncate your logs regularly; logrotate would be helpful in this case.
Comments
0 comments
Article is closed for comments.