如果使用Find或Grep命令在目录中找到特定文件,则删除整个目录 [英] Delete whole Directory if a Specefic File found in it using Find or Grep Command

查看:52
本文介绍了如果使用Find或Grep命令在目录中找到特定文件,则删除整个目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果要使用 find grep 命令

我可以使用此命令搜索包含在特定文本中的文件

I'm able to search a file contained on specefic text using this Command

grep -iRl "Hacked by Hun73rCL4W"

我发现 index(1).html 文件包含我搜索过的特定文本.

As i Found that index (1).html file consist this specefic text i have searched.

现在,我不仅要删除 index(1).html 文件,而且还希望删除由黑客及其父文件夹创建的所有同级文件.在我的情况下是/uixuqkbxmy//trwzqrpaaq/.

Now, Not only I want to remove the index (1).html file but also want to remove it's all siblings files created by the hacker and its parent folder which is /uixuqkbxmy/and /trwzqrpaaq/ in my case.

为此,我创建并搜索了许多如下所示的命令,但所有命令都没有用.

for that purpose, I have created and search many commands like below but all goes in vain not worked.

1.一起使用 find grep 命令搜索文件

1. Search file Using find and grep command Together

find -type f -exec grep -l "Hacked by Hun73rCL4W" {} \;

它只能帮助我找到文件名及其路径.

it only helped me to find the filename and it's path.

2.搜索并删除

找到类型f -exec grep -l被Hun73rCL4W入侵".{};xargs rm -rf

find -type f -exec grep -l "Hacked by Hun73rCL4W" {} ; xargs rm -rf

找到类型f -exec grep -l被Hun73rCL4W入侵".{};-删除

find -type f -exec grep -l "Hacked by Hun73rCL4W" {} ; -delete

这些命令仅帮助我删除了正在搜索的特定文件.

these commands only helped me to delete a specific file that is being searched.

3.这些命令帮助我打印了父目录名称.

找到类型f -exec grep -l被Hun73rCL4W入侵".{};-printf'%h \ n'

find -type f -exec grep -l "Hacked by Hun73rCL4W" {} ; -printf '%h\n'

现在我在下面寻找类似这样的命令

Now I'm looking for a Solution a Command something like this below

找到类型f -exec grep -l被Hun73rCL4W入侵".{};-printf'%h \ n'-exec rm -rf"{}";

find -type f -exec grep -l "Hacked by Hun73rCL4W" {} ; -printf '%h\n' -exec rm -rf "{}" ;

  1. 它应该搜索其中包含特定文本的文件.
  2. 它应删除此文件,包括同级文件和父目录

推荐答案

如何?

grep -ril "Hacked by Hun73rCL4W" | awk -F/ '{$NF="";print}' OFS='/' | xargs rm -rf

似乎为我工作:

$ mkdir -p public_html/wp-content/plugins/{awerwear,asdfse3r,sdfgeh}
$ vim public_html/wp-content/plugins/{awerwear,asdfse3r,sdfgeh}/index\ \(1\).html
$ grep -ril "Hacked by Hun73rCL4W"
public_html/wp-content/plugins/sdfgeh/index (1).html
public_html/wp-content/plugins/asdfse3r/index (1).html
public_html/wp-content/plugins/awerwear/index (1).html
$ grep -ril "Hacked by Hun73rCL4W" | awk -F/ '{$NF="";print}' OFS='/'
public_html/wp-content/plugins/sdfgeh/
public_html/wp-content/plugins/asdfse3r/
public_html/wp-content/plugins/awerwear/
$ grep -ril "Hacked by Hun73rCL4W" | awk -F/ '{$NF="";print}' OFS='/' | xargs rm -rf 
$ find
.
./pines
./public_html
./public_html/wp-content
./public_html/wp-content/plugins

附言:不会使我对您的问题的评论无效;您将处于安全状态或不受黑客攻击";只需删除这些

P.S.: This does not invalidate my comment on your question; you will not be safe or "unhacked" by just removing those

这篇关于如果使用Find或Grep命令在目录中找到特定文件,则删除整个目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆