#!/usr/bin/perl -w use strict; #deletes first numbytes of a file use constant BLOCKSIZE => 128*1024; die "Usage: $0 numbytes file [file ...]\n" if @ARGV < 2; my $trunc_bytes = shift @ARGV; my $files_done = 0; for(@ARGV) { my $fh; unless(open $fh, "+<", $_) { warn "Couldn't open $_: $!\n"; next; } my $filesize = -s $fh; while($filesize > $trunc_bytes + tell $fh) { seek $fh, $trunc_bytes, 1; my $bytes_read = read($fh, my $buffer, BLOCKSIZE); seek $fh, -$bytes_read -$trunc_bytes, 1; print $fh $buffer; } truncate $fh, tell $fh; close $fh; $files_done++; } exit ($files_done == 0);