Results 1 to 9 of 9
Hello, i'm somewhat new to the linux environment. i've been tasked with cleaning up some files.
I need to delete all files that contain a specific phrase, but only if ...
- 02-25-2010 #1Just Joined!
- Join Date
- Feb 2010
- Posts
- 5
Trying to do a Find
Hello, i'm somewhat new to the linux environment. i've been tasked with cleaning up some files.
I need to delete all files that contain a specific phrase, but only if that file resides in a folder that starts with a specific set of letters.
i've googled around quite a bit and what i thought would work, didn't quite work
find . -name "zz.*" -type f -exec grep -l "***SPAM***" {} \; -exec rm {} \;
but it just sits there and spins its wheels, never returning any results..
i've been testing without the -exec rm {} \; part until it shows its returning results.
any help is appreciated.. thanks
- 02-25-2010 #2
-exec rm is going to wait for interaction, since you don't want interaction use
-exec rm -f {}linux user # 503963
- 02-25-2010 #3Just Joined!
- Join Date
- Feb 2010
- Posts
- 5
thanks.. i've added that to the final run statement..
but for some reason its not listing the results when i execute the find
the way i understand it
find . -name "zz.*" -type f -exec grep -l "***SPAM***" {} \;
it should read like
find starting in current directory
filter for names starting with "zz."
pass types of file to grep search inside file for "***SPAM***" inside the "found" file
maybe an example of structure would help
/....../some.user/Maildir/new/ (contains emails)
/....../zz.some.user/Maildir/new (contains a backup of emails)
i want to search inside all directories that start with zz.
look inside all the files inside of the directories found for "***SPAM***"
then remove those files.
thanks.
- 02-25-2010 #4
so if you run each portion of it, does it succeed? the dot is not necessary though, as it would search the present directory
run the find command as you have it
whatever is coming out of your find command is going to be fed verbatim into your grep command, so copy/paste a line from it and put it into the grep commandCode:find -name "zz.*" -type f
Code:grep -l "***SPAM***"
linux user # 503963
- 02-25-2010 #5Just Joined!
- Join Date
- Feb 2010
- Posts
- 5
Ok, i tried those, but apparently there wasn't any results...
so i tweaked it a little bit and got some results
find -name "zz.*" -exec find {} -type f \; -exec grep -l "***SPAM***" {} \; | wc -l
returned
2605591
but then i compared it to one without the grep
find -name "zz.*" -exec find {} -type f \; | wc -l
and it returned
2605618
i'm assuming the difference in the numbers is just due to the time and 20 emails were received...
- 02-25-2010 #6
when i do a find, i make sure that i give it the whole path, try using:
i used -maxdepth 20 just to make sure it would traverse down a ridiculous levelCode:find /path/to/directory -maxdepth 20 -name "zz.*" -type f
linux user # 503963
- 02-25-2010 #7Just Joined!
- Join Date
- Feb 2010
- Posts
- 5
tried the maxdepth and the full path there.. still looks like its just finding every file, instead of reading into the file and finding the ones i want.
find /full/directory/path -maxdepth 20 -name "zz.*" -exec find {} -type f \; -exec grep -l "***SPAM***" {} \; | wc -l
returned with..
2606142
about 100 more than the previous count..
- 02-26-2010 #8Linux User
- Join Date
- Dec 2007
- Location
- Idaho USA
- Posts
- 351
looking at Example uses of the Linux Command find , do not use " " .
and drop the . "period" after the file name, zz.* would look for file name zz with any extension, not for all files that start with zz .Code:find -name zz*
- 02-26-2010 #9Just Joined!
- Join Date
- Feb 2010
- Posts
- 5
i appreciate the tip, i tried without the quotes and it doesn't have any results.
with the quotes, i'm getting what appears to be the proper list.
i'm looking for all directories that start with zz.
there are directories in there that contain zz, but are not the ones i want..
ex : zz.clint.steele is a directory name i am looking for, but i don't want to get the directory clint.buzz.lightyear
and with the list of directories, i want to perform a find inside of those directories and search for any file that contains "***SPAM***" inside of the file.
thanks.


Reply With Quote