From owner-freebsd-questions@FreeBSD.ORG Fri Dec 18 16:33:55 2009 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 5C6731065693 for ; Fri, 18 Dec 2009 16:33:55 +0000 (UTC) (envelope-from wblock@wonkity.com) Received: from wonkity.com (wonkity.com [67.158.26.137]) by mx1.freebsd.org (Postfix) with ESMTP id 10AC48FC41 for ; Fri, 18 Dec 2009 16:33:54 +0000 (UTC) Received: from lightning.wonkity.com (lightning.wonkity.com [10.0.0.8]) by wonkity.com (8.14.3/8.14.3) with ESMTP id nBIGXnRa060216; Fri, 18 Dec 2009 09:33:49 -0700 (MST) (envelope-from wblock@lightning.wonkity.com) Received: from lightning.wonkity.com (localhost [127.0.0.1]) by lightning.wonkity.com (8.14.3/8.14.3) with ESMTP id nBIGXnNF011450; Fri, 18 Dec 2009 09:33:49 -0700 (MST) (envelope-from wblock@lightning.wonkity.com) Received: from localhost (wblock@localhost) by lightning.wonkity.com (8.14.3/8.14.3/Submit) with ESMTP id nBIGXn1O011447; Fri, 18 Dec 2009 09:33:49 -0700 (MST) (envelope-from wblock@lightning.wonkity.com) Date: Fri, 18 Dec 2009 09:33:49 -0700 (MST) From: Warren Block To: perryh@pluto.rain.com Message-ID: User-Agent: Alpine 2.00 (BSF 1167 2008-08-23) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; format=flowed; charset=US-ASCII X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.2.3 (wonkity.com [10.0.0.1]); Fri, 18 Dec 2009 09:33:49 -0700 (MST) Cc: glarkin@freebsd.org, mexas@bristol.ac.uk, freebsd-questions@freebsd.org Subject: Re: editing a binary file X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Dec 2009 16:33:55 -0000 perryh@pluto.rain.com wrote: > Greg Larkin wrote: > > ... > > > truncate -4 myfile should get rid of the last four bytes. Maybe > > > there's a similar efficient way to truncate the start of a file. > > > > This should do it: > > > > dd if=oldfile of=newfile bs=1 skip=4 > > Or, perhaps marginally more efficient: > > dd if=oldfile of=newfile bs=4 skip=1 It would be nice to avoid the file copy, but maybe there's no way to do that. The small buffer size for dd will probably make copies of multi-gig files slow. This might be faster: tail -c +5 myfile > outfile truncate -4 outfile (Has anyone mentioned that you can edit binary files interactively with vi yet? No? Well, it's horrific and surely has interesting failure modes. And there are probably disadvantages also.) -Warren Block * Rapid City, South Dakota USA