?
Solved

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

Posted on 2005-03-02
10
Medium Priority
?
359 Views
Last Modified: 2013-12-16
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
Comment
Question by:stanleyhuen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
10 Comments
 
LVL 16

Expert Comment

by:manav_mathur
ID: 13440349
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
 
LVL 14

Expert Comment

by:chris_calabrese
ID: 13440386
find . -type f -exec grep -l "Merry Christmas" {} ';'
0
 
LVL 16

Expert Comment

by:manav_mathur
ID: 13440401
Chris,

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

Manav
0
Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

 
LVL 14

Expert Comment

by:chris_calabrese
ID: 13440429
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
 
LVL 16

Expert Comment

by:manav_mathur
ID: 13440441
find . -type f -print | xargs grep -l "Merry Christmas"

Manav
0
 
LVL 14

Expert Comment

by:chris_calabrese
ID: 13440486
Good point.
0
 

Author Comment

by:stanleyhuen
ID: 13440769
So,
how to remove them then ???

Do you think the server will hang if we grep 51,000 files ??
0
 
LVL 16

Expert Comment

by:manav_mathur
ID: 13440803
find . -type f -print | xargs grep -l "Merry Christmas" | xargs grep rm -f

Manav
0
 
LVL 16

Accepted Solution

by:
manav_mathur earned 450 total points
ID: 13440809
Damn!!
find . -type f -print | xargs grep -l "Merry Christmas" | xargs rm -f
0
 
LVL 16

Expert Comment

by:manav_mathur
ID: 13441592
I think Chris deserves some points here(I'd say more than me).

Manav
0

Featured Post

Does Your Cloud Backup Use Blockchain Technology?

Blockchain technology has already revolutionized finance thanks to Bitcoin. Now it's disrupting other areas, including the realm of data protection. Learn how blockchain is now being used to authenticate backup files and keep them safe from hackers.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I am a long time windows user and for me it is normal to have spaces in directory and file names. Changing to Linux I found myself frustrated when I moved my windows data over to my new Linux computer. The problem occurs when at the command line.…
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Suggested Courses
Course of the Month14 days, 1 hour left to enroll

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question