From owner-freebsd-questions Fri Jan 3 11: 4:40 2003 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 F297137B405 for ; Fri, 3 Jan 2003 11:04:38 -0800 (PST) Received: from conure.mail.pas.earthlink.net (conure.mail.pas.earthlink.net [207.217.120.54]) by mx1.FreeBSD.org (Postfix) with ESMTP id 6DC4543ED8 for ; Fri, 3 Jan 2003 11:04:38 -0800 (PST) (envelope-from deepbsd@earthlink.net) Received: from user-119a2km.biz.mindspring.com ([66.149.10.150] helo=sylvester.dsj.net) by conure.mail.pas.earthlink.net with esmtp (Exim 3.33 #1) id 18UX7U-00018e-00; Fri, 03 Jan 2003 11:04:36 -0800 Received: from sylvester.dsj.net (dsj@localhost [127.0.0.1]) by sylvester.dsj.net (8.12.3/8.12.3/Debian -4) with ESMTP id h03J4Z4j004055; Fri, 3 Jan 2003 14:04:35 -0500 Received: (from dsj@localhost) by sylvester.dsj.net (8.12.3/8.12.3/Debian -4) id h03J4YMg004054; Fri, 3 Jan 2003 14:04:34 -0500 X-Authentication-Warning: sylvester.dsj.net: dsj set sender to deepbsd@earthlink.net using -f Date: Fri, 3 Jan 2003 14:04:33 -0500 From: "David S. Jackson" To: Danny Cc: questions@FreeBSD.ORG, deepbsd@earthlink.net Subject: Re: Shell guru needed.(xargs question) Message-ID: <20030103190433.GB1925@sylvester.dsj.net> Reply-To: "David S. Jackson" References: <200301030103.h0313b67012698@labs.unixhideout.com> <20030103152501.GA1925@sylvester.dsj.net> <003301c2b340$7e473570$7801a8c0@afi> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <003301c2b340$7e473570$7801a8c0@afi> User-Agent: Mutt/1.4i Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On Fri, Jan 03, 2003 at 10:55:09AM -0500 Danny wrote: > Could you please give another realworld example of using xargs and > your definition of it. I had a glance through man xargs, but I enjoy input > from humans that use it as well. :) Xargs is pretty neat. You have to remember that there are different implementations of it, too, so xargs on Linux would probably be different than xargs on *BSD (it always is different in my experience). The differences would mainly be in switches and default behavior. I use xargs with lots of different utilities, just depending on what I need to do with whatever files I'm catching. For example, let's say I wanted to rename some files: locate *.PDF | xargs -I % mv % `basename % .PDF`.pdf It's handy if you have a bunch of files in one directory that you want to check somehow: ls *.{jpg,gif} | xargs -J % file % | grep -v 'JPEG\|GIF' Moving files to another directory is a popular use: locate *.suf | xargs -J % mv % /path/to/dir Note that you do not always need to use xargs. locate *.PDF | while read name; do mv $name ${name%.PDF}.pdf done There's lots more you can do with it. Your imagination is almost your only limitation. :-) -- David S. Jackson dsj@dsj.net =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= And now for something completely the same. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message