Raptor Asked: 2012-09-13 00:56:41 +0800 CST2012-09-13 00:56:41 +0800 CST 2012-09-13 00:56:41 +0800 CST Install Ubuntu truncate command to Mac OS X 10.7 772 Is there any way to install Ubuntu's truncate command to Mac OS X 10.7 in order to use the command in Terminal shell? mac-osx 4 Answers Voted Best Answer Alex Berry 2012-09-13T01:28:35+08:002012-09-13T01:28:35+08:00 This shouldn't really be in Server Fault, probably Super User or Ask Different, but you can install a lot of binaries by using homebrew, found here: Link Firstly you'll need to install command line tools for Xcode, which will probably require you to purchase it if you havn't already. Once you've done this, run: ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" To install homebrew, then when it's installed, run: brew install truncate Alex Yursha 2015-03-30T03:48:12+08:002015-03-30T03:48:12+08:00 Update: As of March 2015 truncate is no longer available in Homebrew as a standalone formula. As truncate is part of GNU Coreutils you should install it on OS X with the following command: > brew install coreutils After installation truncate will be available under the name gtruncate. Note that all programs from Coreutils will be available with the prefix g. Ian Mackinnon 2012-10-20T08:14:45+08:002012-10-20T08:14:45+08:00 When truncate is not available you can often use dd instead. Eg. Make a file full of zeros: dd if=/dev/zero of=/tmp/youroutputfile bs=1m count=50 Truncate an existing file: dd if=yourinputfile of=/tmp/youroutputfile bs=1k count=1 Note: the OS X dd uses lower case unit letters where GNU dd uses upper case. karmakaze 2017-05-12T19:10:04+08:002017-05-12T19:10:04+08:00 One point of consideration is if the truncated file is the same file or a new file with the same name. Of importance for log files that are still being written-to, or being tailed. :> file Works on both *nix and macOS to truncate a file in-place.
This shouldn't really be in Server Fault, probably Super User or Ask Different, but you can install a lot of binaries by using homebrew, found here:
Link
Firstly you'll need to install command line tools for Xcode, which will probably require you to purchase it if you havn't already.
Once you've done this, run:
To install homebrew, then when it's installed, run:
Update:
As of March 2015
truncate
is no longer available in Homebrew as a standalone formula.As
truncate
is part of GNU Coreutils you should install it on OS X with the following command:> brew install coreutils
After installation
truncate
will be available under the namegtruncate
. Note that all programs from Coreutils will be available with the prefixg
.When
truncate
is not available you can often usedd
instead. Eg.Make a file full of zeros:
Truncate an existing file:
Note: the OS X
dd
uses lower case unit letters where GNUdd
uses upper case.One point of consideration is if the truncated file is the same file or a new file with the same name. Of importance for log files that are still being written-to, or being
tail
ed.:> file
Works on both *nix and macOS to truncate a file in-place.