[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: rm doesnt' delete

From: Brian Dessent
Subject: Re: rm doesnt' delete
Date: Fri, 12 Jan 2007 06:17:14 -0800

Lise Slama wrote:

> I have some trouble with "rm".
> When I do
> rm  --recursive   --verbose   a.out
> or more generally when I use "rm -R", it only deletes the corresponding
> files in the current directory.
> Do you know if there is some thing to configure or some way to correct that?

That is the expected behavior.  "--recursive" does not work the way you
think it does.  It does not mean to recursively look in every directory
for the given filename.  It means that if a directory name is given as
one of the arguments to "rm", to remove it and all its subdirectories.

If you want to remove all instances of a file with a specified name in a
directory tree the best method is to use "find".  If you are only
interested in deleting files then you can use find's -delete option.

find . -name a.out -delete

You can use wildcards with find, but remember that they should be
quoted, as you want "find" to do the wildcard expansion, not the shell:

find . -name 'foo*.bar' -delete

If you wanted to do something other than delete them, then you can use
the "find | xargs" idiom.  For details and examples run "info find" or
"info xargs" and browse.  These commands are extremely flexible and the
way to go for doing most tasks involving recursively searching for all
files of a given specification.  Pretty much the only time that the "-r"
flag to rm is useful is when you want to remove a directory and all its
contents, as in "rm -rf dir".


reply via email to

[Prev in Thread] Current Thread [Next in Thread]