Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
What are you trying to do? –  quanta Sep 12 '12 at 9:04
I have a shell script that makes sure of truncate function, which I want to try it in local Mac. –  Raptor Sep 12 '12 at 10:47

2 Answers 2

up vote 3 down vote accepted

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:


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
share|improve this answer
I found that truncate in homebrew is different than Ubuntu version. It does not have option flag. –  Raptor Sep 12 '12 at 10:47
There's also Fink: finkproject.org and Macports: macports.org you could try, before doing so run brew uninstall truncate, though. –  Alex Berry Sep 12 '12 at 10:56
Also would appreciate an upvote as, regardless of if it worked for you, I did provide a valid answer to your question :) –  Alex Berry Sep 12 '12 at 10:56
Now, using Yosemite the following solved for me (also using home brew: magiclantern.fm/forum/index.php?topic=6407.0 –  tenshimsm Nov 3 '14 at 15:04

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.

share|improve this answer
dd can almost achieve the goal. Can dd truncate from the end of file? As I read from the man file of dd, I know that it can only be read from file beginning. How about I delete last 100 bytes from the file ? –  Raptor Oct 22 '12 at 3:20
Not as far as I know. You'd have to do the target size calculation yourself by reading the file size first and subtracting 100 bytes. –  Ian Mackinnon Oct 22 '12 at 9:38

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.