Re: [nottingham] Recursively act on a certain filetype?

From: Simon Amor (simon@shoe.bocks.com)
Date: Tue 30 Jul 2002 - 21:42:35 BST


David Luff wrote:
>
> which both work nicely. I can certainly appreciate the potential power of
> the approach above (I can see that work avoidance this week is going to
> involve trying to remove files based on the output of grep - and no, don't
> tell me please!) but I'm still curious as to why
> rm -rf *.o
> doesn't simply delete all instances of the pattern recursively from the
> current directory. Given that rm can delete a whole directory tree
> recursively, and can delete non-recursively to a pattern, it would seem an
> almost trivial addition. Is there a good reason for not doing this that
> I'm missing, or is it just the way things are?

*.o is expanded by bash to match any files in the current dir that end
.o - this is done before rm even gets a look-in.
Alternatively, rm -rf '*.o' will prevent the expansion (globbing) but
rm will attempt to find a file or directory literally called "*.o"

It's the globbing that lets it delete non-recursively to a pattern -
bash expands the list of filenames before rm gets it.

Although you said not to tell you about the grep challenge, check out
the -l and -r options.

  Simon

-- 
Simon Amor   simon@shoe.bocks.com    
ICQ:529466   http://shoe.bocks.com/
             GPG/PGP key: 0xF318D5F3
--------------------------------------------------------------------
http://www.lug.org.uk                   http://www.linuxportal.co.uk
http://www.linuxjob.co.uk               http://www.linuxshop.co.uk
--------------------------------------------------------------------



This archive was generated by hypermail 2.1.3 : Tue 30 Jul 2002 - 21:42:37 BST