如何製作一個Bash shell腳本,可以識別所有的.jpg,.gif和.png文件,然後確定哪些文件沒有通過url(),href或src鏈接到任何文本文件中一個文件夾?如何讓Bash腳本在項目中查找未使用的圖像?
這是我開始的,但我最終得到了我想要的結果。我不想知道引用的圖像,但未引用(又名「孤兒」)圖像:
# 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?
請將代碼放入您的文章中,而不是通過鏈接。 – plundra