SSH命令查找并删除所有包含字符串的文件
SSH command to find and delete all files that contain a string
我需要使用 SSH 查找所有包含特定字符串(恶意软件)的文件并删除这些文件。
这是我用来查找和显示这些恶意软件文件列表的命令:
find * -name '*.php' -exec grep -l "return base64_decode(" {} \;
我得到这样的列表:
我想删除所有这些文件(不只是显示它们的列表)。
基本上"find all files that contain a string, and delete those files".
您可以说管道 xargs rm
以便删除给定的文件名:
find * -name '*.php' -exec grep -l "return base64_decode(" {} \; | xargs rm
您还可以存储 find
的当前输出,然后循环执行 rm <file>
:
的内容
find ... > file
while IFS= read -r file
do
rm "$file"
done < file
我需要使用 SSH 查找所有包含特定字符串(恶意软件)的文件并删除这些文件。
这是我用来查找和显示这些恶意软件文件列表的命令:
find * -name '*.php' -exec grep -l "return base64_decode(" {} \;
我得到这样的列表:
我想删除所有这些文件(不只是显示它们的列表)。
基本上"find all files that contain a string, and delete those files".
您可以说管道 xargs rm
以便删除给定的文件名:
find * -name '*.php' -exec grep -l "return base64_decode(" {} \; | xargs rm
您还可以存储 find
的当前输出,然后循环执行 rm <file>
:
find ... > file
while IFS= read -r file
do
rm "$file"
done < file