Hi there,
Really silly question: how can I recursively remove all
files in or below a given directory that match a patttern,
such as "*.old". Am I missing something, or is this not
as easy as "rm -r *.old" ?
-Bob
Really silly question: how can I recursively remove all
files in or below a given directory that match a patttern,
such as "*.old". Am I missing something, or is this not
as easy as "rm -r *.old" ?
-Bob
rm -r *.old
will only remove file ending in ".old" from the current directory. The
following, however will work:
find . -name \*.old -type f -exec rm {} \;
>Really silly question: how can I recursively remove all
>files in or below a given directory that match a patttern,
>such as "*.old". Am I missing something, or is this not
>as easy as "rm -r *.old" ?
>-Bob
find $DIR -type f -name '*.old' | xargs rmQuote:> Hi there,
> Really silly question: how can I recursively remove all
> files in or below a given directory that match a patttern,
> such as "*.old". Am I missing something, or is this not
> as easy as "rm -r *.old" ?
If you may encounter files with spaces in their names:
find $DIR -type f -name '*.old' -exec rm {} \;
Or, with GNU find:
find $DIR -type f -name '*.old' -printf "\"%p\"\n" | xargs rm
--
Chris F.A. Johnson http://cfaj.freeshell.org
===================================================================
My code (if any) in this post is copyright 2002, Chris F.A. Johnson
and may be copied under the terms of the GNU General Public License
That fails if filenames have double-quotes or backslashes in them.Quote:>If you may encounter files with spaces in their names:
>...
>Or, with GNU find:
> find $DIR -type f -name '*.old' -printf "\"%p\"\n" | xargs rm
gfind $DIR -type f -name '*.old' -print0 | gxargs -0 rm --
John
--
> > find $DIR -type f -name '*.old' -printf "\"%p\"\n" | xargs rm
> That fails if filenames have double-quotes or backslashes in them.
Spaces in file names are bad enough, but are, generally, easily
handled.
--Quote:> If you have GNU find, you probably have GNU xargs. I'm very much a fan of null
> filename separation, enough so that I make sure my own utilities support it.
> gfind $DIR -type f -name '*.old' -print0 | gxargs -0 rm --
> > >If you may encounter files with spaces in their names:
> > >...
> > >Or, with GNU find:
> > > find $DIR -type f -name '*.old' -printf "\"%p\"\n" | xargs rm
> > That fails if filenames have double-quotes or backslashes in them.
> Quite true; but I consider such things aberrations, and I do not
> support them unless the specific situation calls for it. (And what it
> usually calls for is a script to convert the names to sane ones as
> quickly as possible.)
Of course aberrant filenames aren't the only issue, some race
conditions involved are really hard to fix if other people
(processes) can mess with the directory tree at the same time
(like in the case of clearing /tmp).
--
Tapani Tarvainen
> rm -r *.old
> will only remove file ending in ".old" from the current directory. The
> following, however will work:
> find . -name \*.old -type f -exec rm {} \;
-Bob
1. Can I recursively remove files ??
3. recursively removing only selected files
5. Visual Bell
6. Removing funny files (Re: how do i remove a file with a ~ in it ????)
7. How can I associate a command to a file?
8. Can't remove a file called "---remove-files"
9. How to remove a dir recursively?
10. Removing recursively hard linked directory
11. Removing single quote from filenames (recursively)