如何编写一个Bash shell脚本,以识别文件夹中所有的.jpg、.gif和.png文件,并确定这些文件中哪些没有在任何文本文件中通过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?
images
的目录中的图像,我会执行./orphancheck.sh <我的图像文件夹路径>
? - Blessing