如何使一个bash脚本找到项目未使用的图片? [英] How Do I Make a Bash Script To Find Unused Images in a Project?

查看:118
本文介绍了如何使一个bash脚本找到项目未使用的图片?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何做的Bash shell脚本,它可以识别所有的个.jpg,.gif和.png文件,然后找出任何文本文件这些文件不是通过网址(),HREF,SRC或链接在文件夹中?

这是我开始的,但我最终得到我想要的倒数。我不想知道引用的图像,但未引用(又名孤立)图像:

 #更改mypath中来,你有这个项目的路径
找到mypath中-name * .JPG -exec基本名称{} \\; >的/ tmp /图案
找到mypath中-name *巴纽-exec基本名称{} \\; >>的/ tmp /图案
找到mypath中-name * .gif注意-exec基本名称{} \\; >>的/ tmp /图案#打印引用这些文件行的列表
#cat命令仅仅删除着色
grep的-Rf的/ tmp /图案mypath中|猫#大 - 但我怎么打印的/ tmp /模式*不*在任何给定列出的行
#* .PHP,*的.css,或* .HTML?


解决方案

通过 drysdam 的帮助下,我创造了这个bash脚本,我称之为orphancheck.sh和./orphancheck.sh MyFolder的呼。

 #!/斌/庆典mypath中= $ 1找到$ mypath中-name * .JPG -exec基本名称{} \\; >的/ tmp /图案
找到$ mypath中-name *巴纽-exec基本名称{} \\; >>的/ tmp /图案
找到$ mypath中-name * .gif注意-exec基本名称{} \\; >>的/ tmp /图案在$ P(猫的/ tmp /图案);做
    grep的-R $ P$ mypath中>的/ dev / null的||回声$ P;
DONE

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?

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:

# 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?

解决方案

With drysdam's help, I created this Bash script, which I call orphancheck.sh and call with "./orphancheck.sh myfolder".

#!/bin/bash

MYPATH=$1

find "$MYPATH" -name *.jpg -exec basename {} \; > /tmp/patterns
find "$MYPATH" -name *.png -exec basename {} \; >> /tmp/patterns
find "$MYPATH" -name *.gif -exec basename {} \; >> /tmp/patterns

for p in $(cat /tmp/patterns); do
    grep -R $p "$MYPATH" > /dev/null || echo $p;
done

这篇关于如何使一个bash脚本找到项目未使用的图片?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆