【发布时间】:2011-12-30 23:13:49
【问题描述】:
如何制作一个可以识别所有 .jpg、.gif 和 .png 文件的 Bash shell 脚本,然后识别这些文件中的哪些文件没有通过任何文本文件中的 url()、href 或 src 链接在文件夹中?
这是我开始的,但我最终得到了与我想要的相反的结果。我不想知道引用的图像,而是未引用(又名“孤立”)的图像:
# Change MYPATH to the path where you have the project
find MYPATH -name *.jpg -exec basename {} \; > /tmp/patterns
find MYPATH -name *.png -exec basename {} \; >> /tmp/patterns
find MYPATH -name *.gif -exec basename {} \; >> /tmp/patterns
# Print a list of lines that reference these files
# The cat command simply removes coloring
grep -Rf /tmp/patterns MYPATH | cat
# great -- but how do I print the lines of /tmp/patterns *NOT* listed in any given
# *.php, *.css, or *.html?
【问题讨论】: