#!/bin/bash
#基于zenity GUI 的脚本
#使用前请先安装 sudo apt install zenity
#该脚本的作用 显示匹配字符文件 路径 以及在哪一行
FGF_B='====================================================='
FGF_D=`printf %-55.5s`
FGF_C=`printf %-50s`
if [ ! -f "/bin/zenity" ];then
zenity --error --width=380 --title="错误信息" --text="$FGF_B\n||$FGF_C你没有安装 zenity$FGF_C||\n$FGF_B"
else
echo "zenity OK"
fi
#自定义函数 myfind
myfind()
{
echo -e "查询速度与你 电脑配置有关 请耐性等待\r开始查询 包含 $name_text 字符的文件 并显示路径行号 查询结束后 ===> 会显示完成\r"
mygrep()
{
#删除显示 二进制文件 以及 不需的文件
grep -rEn "${name_text}" "${name_dir}" | grep -v "Binary file" | sed -e "$name_false"
}
mygrep
echo "查询到 `mygrep | wc -l` 条"
echo -e "\r查询以完成"
}
VideoTitle="查询包含指定字符的文件"
#查询的路径,每个路径用 | 分开
Box_dir="/home/$USER|/opt|/usr|/srv|/var|/sys|/tmp|/proc|/run|/etc|/cdrom|/dev|/bin|"
name_text_a=""
while true ; do
#选择查询路径 对话框
name_dir=$(zenity --forms --width=520 --height="150" --title="$VideoTitle" --text="选择查询路径" --add-combo="请选择" --combo-values="$Box_dir") || exit
if [ -z "$name_dir" ];then
zenity --error --width=380 --height=150 --title="选择错误" --text "$FGF_B\n||$FGF_D选择不能为空$FGF_D||\n$FGF_B"
else
break;
fi
done
while true ; do
#输入字符 对话框
name_text=$(zenity --entry --width=520 --title="$VideoTitle" --text="请输入字符" --entry-text="$name_text_a" )
if [ -z "$name_text" ];then
zenity --error --width=380 --height=150 --title="输入错误" --text "$FGF_B\n||$FGF_D输入不能为空$FGF_D||\n$FGF_B"
else
break;
fi
done
while true ; do
#选择删除显示哪些格式的文件 对话框
name_false=$(zenity --list --width=520 --height=350 --title="$VideoTitle" --text "选择排除的格式" --checklist \
--column "选择" --column "选项" \
FALSE "/.json/d;" FALSE "/.log/d;" FALSE "/.txt/d;" \
FALSE "/.py/d;" FALSE "/.htm*/d;" FALSE "/.php/d;" \
FALSE "/.js/d;" FALSE "/.conf/d;" FALSE "/.reg/d;" \
--separator="")
if [ -z "$name_false" ];then
zenity --error --width=380 --height=150 --title="选择错误" --text "$FGF_B\n||$FGF_D选择不能为空$FGF_D||\n$FGF_B"
else
break;
fi
done
myfind | zenity --text-info --title="$VideoTitle" --width=800 --height=600 || exit
04-17
1644
09-27
339