From owner-freebsd-questions@FreeBSD.ORG Tue Dec 9 09:56:32 2003 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id BB4F516A4CE for ; Tue, 9 Dec 2003 09:56:32 -0800 (PST) Received: from smtpout.mac.com (A17-250-248-44.apple.com [17.250.248.44]) by mx1.FreeBSD.org (Postfix) with ESMTP id 4416B43D29 for ; Tue, 9 Dec 2003 09:56:31 -0800 (PST) (envelope-from cswiger@mac.com) Received: from mac.com (smtpin07-en2 [10.13.10.152]) by smtpout.mac.com (Xserve/MantshX 2.0) with ESMTP id hB9HxnoW006860; Tue, 9 Dec 2003 09:59:49 -0800 (PST) Received: from [192.168.1.6] (pool-68-161-96-170.ny325.east.verizon.net [68.161.96.170]) (authenticated bits=0)hB9HuUhc008050; Tue, 9 Dec 2003 09:56:30 -0800 (PST) In-Reply-To: <20031209015125.74977.qmail@web14806.mail.yahoo.com> References: <20031209015125.74977.qmail@web14806.mail.yahoo.com> Mime-Version: 1.0 (Apple Message framework v594) Content-Type: text/plain; charset=US-ASCII; format=flowed Message-Id: <09F412E2-2A71-11D8-A16D-003065A20588@mac.com> Content-Transfer-Encoding: 7bit From: Charles Swiger Date: Tue, 9 Dec 2003 12:56:39 -0500 To: homeyra g X-Mailer: Apple Mail (2.594) cc: freebsd-questions@FreeBSD.org Subject: Re: a technical how to X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 09 Dec 2003 17:56:32 -0000 On Dec 8, 2003, at 8:51 PM, homeyra g wrote: > Here is the question: How to truncate a file from the > begining to a certain point in the file? The question is whether this file is ASCII text so line-based tools (such as tail) work, or whether you are truncating a binary file, in which case "split -b" is probably a better bet. If you've got a logfile named /var/log/messages, and you want to truncate that to the last 100 lines: mv /var/log/messages /var/log/messages.$$ tail -100 < /var/log/messages.$$ > /var/log/messages rm -f /var/log/messages.$$ Use "wc -l" and "grep -n" to identify where to truncate the file if it's not a fixed size that you want... -- -Chuck