Hi
There are many ways to achieve what you want. Here is one way.
You can do something like:
find <YourDir> -name <pattern> | xargs rm
For example, let's say you have a directory structure as following:
Mars/
Mars/moon1
Mars/moon2
Mars/star1
Mars/star2
Jupiter/
Jupiter/moon1
Jupiter/moon2
Jupiter/star1
Jupiter/star2
Saturn/
Saturn/moon1
Saturn/moon2
Saturn/star1
Saturn/star2
Let's say all the above dir's are under the directory 'solar' & you want
to delete all 'moon' files.
So you do the following:
cd solar
find . -name 'moon*' | xargs rm
WARNING: Always think before you execute rm !!! There's no default
undelete in ext2fs !
For details, man find & man xargs.
Tip: xargs is a command which can read from stdin & execute a given
command, passing the stdin data to the command line of the command being
executed. I've had good use of the combination of find & xargs.
Sreeji
On Sat, 16 Dec 2000, Neeraj Manral wrote:
> Hello sirs ,
> Thanks a lot for all the earlier help!
>
> Is there any commands in linux which shall remove all the files having a
> particular string in filename from all the folders in a particular directory
> .
>
> suppose the filename has a string "XYZ!@#$%" common in all the folders .
> what command should i give to del all the files in various folders under dir
> xyz
>
> Directory (xyz)
>
> folder1 folder 2 folder 3
> XYZ!@#$% XYZ!@#$% XYZ!@#$%
>
> I am not able to figure out how to use rm command with grep.
>
> Thanks & Regards
> Neeraj
>
>
> ----------------------------------------------
> An alpha version of a web based tool to manage
> your subscription with this mailing list is at
> http://lists.linux-india.org/cgi-bin/mj_wwwusr
>
----------------------------------------------
LIH is all for free speech. But it was created
for a purpose. Violations of the rules of
this list will result in stern action.