delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2002/03/04/07:56:54

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Date: Mon, 4 Mar 2002 13:56:21 +0100 (MET)
From: Bjoern Kahl AG Resy <kahl AT informatik DOT uni-kl DOT de>
To: Serge Beaumont <beaumose AT iquip DOT nl>
cc: cygwin AT cygwin DOT com
Subject: Re: 1.13.10-1: recursive rm and ls don't work (Win98)
In-Reply-To: <000701c1c378$380aac80$0d0a10ac@iquip.nl>
Message-ID: <Pine.GSO.4.44.0203041335280.2167-100000@domino.informatik.uni-kl.de>
MIME-Version: 1.0

 Hello !

On Mon, 4 Mar 2002, Serge Beaumont wrote:
> I downloaded and installed the base version of Cygwin today. I think I found
> a bug and did not find an answer in the FAQ and mailing list archives.

 It is not a bug, it is a feature
 to understand this, you should keep in mind, how pattern-matching works.

> I wanted to remove the *.~* files that Delphi always leaves behind in my
> development directory. These commands I tried will not work recursively,
> they only find the items in the current working directory:
> rm -rf *.~*
> ls -r *.~*
> ls -r *.pas

 In Cygwin (as in unix) Patern are expandet by the shell, not by the
called programm. So These lines aktually read

 "ls -r bla.~  foo.~bar  ..."

 That is, "ls" will find a number of files, but now directory on
 its commandline arguments.
 Of course only a directory could be listed recursivly.
 So there is simoly no entity on "ls" commandline, to which the
 "-R" could be applied.

> ls -r *
> works!

 In this case, ls will find all files _and_ all (sub-)directorys
 on its commandline. so it can apply the "-R" switch to the
 directorys.

 So how to go?

 Well, you want to try "find". Something like
 "find . -iname \*.~\* -o -iname \*.pas | xargs -r -n 20 rm -f"

 What will this line do?

 First, we instruct find to start searching in the current
 directory ("find ."). Then we request to match each found file
 against the pattern "*.~*". The "\" Prevents the shell from
 replacing "*.~*" with "bla.~  foo.~bar" ("-iname \*.~\*").
 Because we want to find more patterns, we request to check
 in addition against "*.pas" ("-o -iname \*.pas"). The "-o"
 stands for "logical or". Each test in find ("-iname ...")
 evaluates to "true" if it matches or "false" if not. Find
 terminates the evaluation as soon as it konw the out come
 of the whole expression. If it is "true" it prints the
 matched entity, otherwise it starts the next cycle.

 The Rest of the line pipes the List of filesnames from "find"
 into xargs, which collects 20 ("-n 20"), creates a new
 commandline from its remining arguments ("rm -f") and these 20
 entites and runs that commnadline. The "-r" prevents xargs from
 running an empty commandline, in case there are no files found
 by "find".

 For details and the higher magic of shell programming you
 should consult the manpages.


   Bjoern

-- 
+---------------------------------------------------------------------+
| Dipl.-Phys. Bjoern Kahl +++ AG Embedded Systems and Robotics (RESY) |
| Informatics Faculty +++ Building 48 +++ University of Kaiserslautern|
| phone: +49-631-205-2654 +++ www: http://resy.informatik.uni-kl.de   |
+---------------------------------------------------------------------+


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019