Re: -R switch in rm command doesn't...
- From: "Chris F.A. Johnson" <cfajohnson@xxxxxxxxx>
- Date: Sat, 25 Feb 2006 18:17:50 -0500
On 2006-02-25, Robert Newson wrote:
Ian Northeast wrote:
On Sat, 25 Feb 2006 19:30:55 +0000, Gordon wrote:
I am trying to remove files which all have the same part of a file name
that exist in sub-directories of sub-directories - the -R switch only
seems to go down one level not two or more. is that just a limitation of
the -R switch, or am I doing something wrong?
If I read you correctly, you are trying to remove files whose names match
a particular pattern, whereever they are in a particular hierarchy. If so,
you want the find command with the "-exec rm" switch. It's probably best
to test it with an "ls" in place of the "rm" first, so you can check what
will be deleted without actually deleting anyting.
Probably better (in terms of processes invoked) to use -print0 with find
piped into xargs -0, as in:
$ find <criteria> -print0 | xargs -0 <command_to_process_files and initial args>
especially when there will be a lots of files. (You can always use "echo"
as a prefix to the command_to_process_files to check you're getting what
you're expecting.)
With a POSIX version of find (such as recent GNU versions), you
don't need xargs:
find <criteria> -exec <command_to_process_files and initial args> {} +
Note the '+' instead of '\;'; it supplies as many arguments as it
can to the command, just as xargs does.
--
Chris F.A. Johnson <http://cfaj.freeshell.org>
===================================================================
Author:
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
.
- Follow-Ups:
- Re: -R switch in rm command doesn't...
- From: Robert Newson
- Re: -R switch in rm command doesn't...
- References:
- -R switch in rm command doesn't...
- From: Gordon
- Re: -R switch in rm command doesn't...
- From: Ian Northeast
- Re: -R switch in rm command doesn't...
- From: Robert Newson
- -R switch in rm command doesn't...
- Prev by Date: Re: -R switch in rm command doesn't...
- Next by Date: Re: -R switch in rm command doesn't...
- Previous by thread: Re: -R switch in rm command doesn't...
- Next by thread: Re: -R switch in rm command doesn't...
- Index(es):
Relevant Pages
|
|