Re: -R switch in rm command doesn't...



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)
.



Relevant Pages

  • Re: rm limitation ?
    ... is it possible to get rid of the limitation of number of files that can ... deleted in a "rm something*" command? ... ls |xargs -n1 rm ...
    (comp.unix.aix)
  • Re: -R switch in rm command doesnt...
    ... you want the find command with the "-exec rm" switch. ... will be deleted without actually deleting anyting. ...
    (uk.comp.os.linux)
  • Re: C2960 config - What do the commands do
    ... To enable visible sequence numbering of system logging messages, use the service sequence-numbers command in global configuration mode. ... Configure the system to automatically switch to summer time. ... This sybnet has the same network address what main network (the subnetted one) but longer subnet mask ... For chassis with 64 MAC addresses, STP uses the extended system ID plus a MAC address to make the bridge ID unique for each VLAN. ...
    (comp.dcom.sys.cisco)
  • Re: proposal: reswitch
    ... > which levels of loops and/or switches and/or ... socket -server command ?-myaddr addr? ... You've got the quick-exit (break, no string), the fall-through to next ... -switch option), then it'd be the nth switch. ...
    (comp.lang.tcl)
  • voice activated Windows shortcuts
    ... It works if the command pause is set to .1 seconds and the ... dictation while in Command Mode and AFAIK there's no hotkey to switch ... switching between windows does not ... back space (click, Backspace, Space) ...
    (comp.speech.research)