From owner-freebsd-questions@FreeBSD.ORG Sat Jan 19 00:18:55 2013 Return-Path: Delivered-To: questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 4D58F756 for ; Sat, 19 Jan 2013 00:18:55 +0000 (UTC) (envelope-from chris@monochrome.org) Received: from mail.monochrome.org (b4.ebbed1.client.atlantech.net [209.190.235.180]) by mx1.freebsd.org (Postfix) with ESMTP id 0F69FF7D for ; Sat, 19 Jan 2013 00:18:54 +0000 (UTC) Received: from [192.168.1.11] ([192.168.1.11]) by mail.monochrome.org (8.14.3/8.14.3) with ESMTP id r0INpBIV049360; Fri, 18 Jan 2013 18:51:11 -0500 (EST) (envelope-from chris@monochrome.org) Date: Fri, 18 Jan 2013 18:51:11 -0500 (EST) From: Chris Hill To: Fbsd8 Subject: Re: sh script code to get file size. In-Reply-To: <50F9DA3E.5050607@a1poweruser.com> Message-ID: References: <50F9DA3E.5050607@a1poweruser.com> User-Agent: Alpine 2.00 (BSF 1167 2008-08-23) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Cc: FreeBSD questions X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 19 Jan 2013 00:18:55 -0000 On Fri, 18 Jan 2013, Fbsd8 wrote: > In a script in am working on I need to find out the allocated > size of a sparse file. > The only command that comes to mind is "ls -lh" > The "du -h" command is not appropriate because it will show > the occupied size and not the allocated size. > > I don't know how to parse out to the position in the output of that > "ls -lh" command to pickup the file size value. > > Is there some other way to do this? To parse it out, I've used something like: $ ls -lh npviewer.bin.core | cut -d \ -f 9 186M After the backslash are two spaces: one being the space that's being escaped to make it the delimiter, the other to separate the options. The number after the '-f' determines which "field" of the output is displayed, which may vary. HTH. -- Chris Hill chris@monochrome.org ** [ Busy Expunging ]