stanleyhuen
asked on
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 ?
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 ?
find . -type f -exec grep -l "Merry Christmas" {} ';'
Chris,
Wont this increase the number of calls to grep than including xargs??
<I forgot the -f check>
Manav
Wont this increase the number of calls to grep than including xargs??
<I forgot the -f check>
Manav
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
find . -type f -print | xargs grep -l
find . -type f -print | xargs grep -l "Merry Christmas"
Manav
Manav
Good point.
ASKER
So,
how to remove them then ???
Do you think the server will hang if we grep 51,000 files ??
how to remove them then ???
Do you think the server will hang if we grep 51,000 files ??
find . -type f -print | xargs grep -l "Merry Christmas" | xargs grep rm -f
Manav
Manav
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
I think Chris deserves some points here(I'd say more than me).
Manav
Manav
you can do soemthing like
find . -name "*" | xargs grep "Merry Christmas"
Manav