Wed, 09 Apr 2008

How to truncate a file the UNIX way

Astonishingly a search for 'truncate unix utility' doesn't turn up anything useful
apart from hundreds of references to the ftruncate man page.
This is how I did it:

dd of=destfile bs=1 seek=newsize count=1 </dev/null

where newsize can be 1k, 400G, whatever and destfile is obviously the
destination filename.

posted at 20:35 | path: /unix | permanent link to this entry

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.