Mail Archives: cygwin/2002/03/04/07:56:54
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 -