title: How Do I Make a Bash Script To Find Unused Images in a Project?
body: <p>How do I make a Bash shell script that can identify all the .jpg, .gif, and .png files, and then identify which of these files are not linked via url(), href, or src in any text file in a folder?</p>
  
  <p>Here's what I started, but I end up getting the inverse of what I want. I don't want to know referenced images, but unreferenced (aka "orphaned") images:</p>
  
  <pre><code># Change MYPATH to the path where you have the project
  find MYPATH -name *.jpg -exec basename {} \; &gt; /tmp/patterns
  find MYPATH -name *.png -exec basename {} \; &gt;&gt; /tmp/patterns
  find MYPATH -name *.gif -exec basename {} \; &gt;&gt; /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?
  </code></pre>