dennisdominic
asked on
Delete Lists of Files after grep in Linux
Linux Environment.
I have a command that lists all files containing the text '***SPAM***', take the list, and delete All of them.
this command lists all files containing text 'some text'.. but I'm not sure if it applies for '***SPAM***'
grep -lir "some text" *
I have a command that lists all files containing the text '***SPAM***', take the list, and delete All of them.
this command lists all files containing text 'some text'.. but I'm not sure if it applies for '***SPAM***'
grep -lir "some text" *
Whoops, forgot the * at the end of the grep
grep -lir '***SPAM***' *
grep -lir '***SPAM***' *
fgrep -lir '***SPAM***' *
ASKER
Sorry, I mean
take the result list, and delete All of them.
your command gives the list.. so how do I get the system delete all those listed?
take the result list, and delete All of them.
your command gives the list.. so how do I get the system delete all those listed?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
It goes into a very long pause when I run it on the main directory containing 100 Subdirectories of email accounts with over 2000 emails each. But it works very fast when I run it in each of the the email account subdirectories.
I was trying to delete backup emails that are listed as SPAM.
rm -vf `fgrep -lir '***SPAM***' *`
I was trying to delete backup emails that are listed as SPAM.
rm -vf `fgrep -lir '***SPAM***' *`
I'm not surprised you get a pause when trying to run it over >200000 files.
ASKER
I'm trying to make it work by not timing itself out, by going into the Sub Directory first before running the command... so I came up with this..
ls -1 *2 | while read DIR
do
cd "$DIR"
rm -vf `fgrep -lir '***SPAM***' *`
cd ..
done
result:
bash: cd: a2:: No such file or directory
what did I do wrong again?
ls -1 *2 | while read DIR
do
cd "$DIR"
rm -vf `fgrep -lir '***SPAM***' *`
cd ..
done
result:
bash: cd: a2:: No such file or directory
what did I do wrong again?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
It still goes into a very long pause..
for dir in /path/to/dir/*2
do
rm -vf `fgrep -lir '***SPAM***' *`
done
But I can always go back to the original statement and run it manually on a few bigger subdirectories.
rm -vf `fgrep -lir '***SPAM***' *`
for dir in /path/to/dir/*2
do
rm -vf `fgrep -lir '***SPAM***' *`
done
But I can always go back to the original statement and run it manually on a few bigger subdirectories.
rm -vf `fgrep -lir '***SPAM***' *`
I notice you didn't copy/paste my script correctly.
You had
rm -vf `fgrep -lir '***SPAM***' *`
instead of
rm -vf `fgrep -lir '***SPAM***' $dir`
the first version would be additionally slow as it would grep through all the files for as many directories existed.
You had
rm -vf `fgrep -lir '***SPAM***' *`
instead of
rm -vf `fgrep -lir '***SPAM***' $dir`
the first version would be additionally slow as it would grep through all the files for as many directories existed.
ASKER
Thanks!!
I just realised I have to change /path/to/dir into the actual directory.. now it works perfectly!!
for dir in /xvmailhome/domains/MyDoma ins/*2
do
rm -vf `fgrep -lir '***SPAM***' $dir`
done
I just realised I have to change /path/to/dir into the actual directory.. now it works perfectly!!
for dir in /xvmailhome/domains/MyDoma
do
rm -vf `fgrep -lir '***SPAM***' $dir`
done
grep -lir '***SPAM***'