• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 361
  • Last Modified:

How to remove HUGE FILES that contain the same String in Command Line ??

Hello,

I got HUGE  virus emails in my client's email accounts .
His account got almost 51,000 emails . ( he has not check email very long time )

All of these email are under a folder in a linux server .

Of course , Some of them are useful email and the others are virus emails .

I found that most of  virus email contains the word "Merry Christmas!" .

WHat i need to do is
1) find all the emails contain that string
2) remove all of them

I have tried to do the first part using this command

[root@mail1 cur]# grep "Merry Christmas" *
-bash: /bin/grep: Argument list too long


However , i got this message
-bash: /bin/grep: Argument list too long

( because i am talking about 51,000 emails )

Anyone can help ?


0
stanleyhuen
Asked:
stanleyhuen
  • 6
  • 3
1 Solution
 
manav_mathurCommented:
Yes, for 51000 filenames wont fit into the command line buffer I believe.
you can do soemthing like

find . -name "*" | xargs grep "Merry Christmas"

Manav
0
 
chris_calabreseCommented:
find . -type f -exec grep -l "Merry Christmas" {} ';'
0
 
manav_mathurCommented:
Chris,

Wont this increase the number of calls to grep than including xargs??
<I forgot the -f check>

Manav
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
chris_calabreseCommented:
Yeah, it might be faster with xargs, though it doesn't always work if the file names have spaces in them.

find . -type f -print | xargs grep -l
0
 
manav_mathurCommented:
find . -type f -print | xargs grep -l "Merry Christmas"

Manav
0
 
chris_calabreseCommented:
Good point.
0
 
stanleyhuenAuthor Commented:
So,
how to remove them then ???

Do you think the server will hang if we grep 51,000 files ??
0
 
manav_mathurCommented:
find . -type f -print | xargs grep -l "Merry Christmas" | xargs grep rm -f

Manav
0
 
manav_mathurCommented:
Damn!!
find . -type f -print | xargs grep -l "Merry Christmas" | xargs rm -f
0
 
manav_mathurCommented:
I think Chris deserves some points here(I'd say more than me).

Manav
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 6
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now