Removing all files from a folder with by searching for a string in unix
I'm working on a solaris box. How do I go about deleting all files in a folder, which have the word"Failure" in them ?
i'm trying something in the lines of the following, but it doesn't seem to remove anything.
开发者_开发百科rm -rf | find ./*.log -exec grep 'Failure' \;
Appreciate your inputs.
If I interpret correctly you don't require recursive searching, so something like:
rm -f `grep -m 1 'Failure' ./*.log | cut -d: -f1`
should work. If not, try:
rm -f `grep 'Failure' ./*.log | cut -d: -f1 | uniq`
find . -type f -name \*Failure\* -exec rm {} \;
You have to turn that around. Use find to locate the files and then use the -exec option with the rm command.
精彩评论