#!/bin/sh # truncate for linux # Author: P@draigBrady.com # V1.0 16 Dec 2005 Initial release # This is a thin (but useful) wrapper around the # IMHO confusing truncate functionality of dd. # Note the FreeBSD util allows one to specify relative sizes, # and to raise an error if the file doesn't exist. if [ "$#" != "2" ]; then ( echo " Usage: `basename $0` Truncate the to exactly bytes. If doesn't exist it is created. is a number which may be optionally followed by the following multiplicative suffixes: b 512 KB 1000 K 1024 MB 1000*1000 M 1024*1024 and so on for G, T, P, E, Z, Y If the file previously was larger than this size, the extra data is lost. If the file previously was shorter, it is extended and the extended part reads as zero bytes. Note in both cases no data is written (if the filesystem supports holes in files). E.G.: truncate 2TB ext3.test " ) >&2 exit 1 fi size=$1 file="$2" error=`dd bs=1 seek=$size if=/dev/null of="$file" 2>&1` ret=$? echo "$error" | grep -v "^0" >&2 exit $ret