Truncate large log files to zero bytes on OS X

On Linux there’s simple truncate command to achieve that. Truncate however is not available on OS X by default. Here’s a quick tutorial how to install and use truncate using MacPorts.

Installation

  1. Install MacPorts
  2. In Terminal run sudo port install truncate and wait for process to end. You’ll be asked to enter an admin password to install command. It won’t print any characters, just hit Enter after you enter the password.
  3. Happy truncating

Usage

Run truncate in Terminal to see manual.

Mine looked like this:

$ truncate
truncate v0.3, (C) by [ANTISPAM: email removed]

Usage: file [new size]
If new size is omitted, the file will be truncated
to 0 bytes.

Example

Truncate MAMP PHP error log to zero length

truncate /Applications/MAMP/logs/php_error.log

Hope it helps.