删除未从 html 文件链接的文件

删除未从 html 文件链接的文件

给定一个 html 文件(例如 myfile.html)和一个文件夹,其中的一些文件是网页的一部分,而其他文件则未在 html 中链接。

如何删除未链接的文件?

答案1

如果我们接受这一点,我们将把名称在文件中显示为字符串的任何内容都算作链接(这可能不是严格意义上的链接,但至少在我看来让事情变得更容易一些):

for candidate in folder/*; do
    if ! grep -q "$candidate" myfile.html; then
        rm "$candidate"
    fi
done

相关内容