简化grep 命令 grep -r include=*.* lang .

本文介绍如何利用bash脚本简化文件搜索过程,包括通过类型筛选和颜色自动显示来快速定位所需文件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、简化为如下:

langxw@le:~/langxwsh$ cat gr.sh
echo find.s1: $1 ,  type.s2: $2
type=*
#test $2 -eq c
# if [ ] if 和 [ ] 直接必须加上空格,变量赋值=两边不能用空格
if [ $2 = c ]; then
    type=c
elif [ $2 = h ]; then
    type=h
elif [ $2 = cpp ]; then
    type=cpp
elif [ $2 = java ]; then
    type=java
elif [ $2 = xml ]; then
    type=xml
else
    type=*
fi
    
#grep -rn --include=*.$2 $1 --color=auto .
grep -rn --include=*.$type $1 --color=auto .


2、

在 ~/.bashrc 中添加别名

alias gr="source ~/langxwsh/gr.sh"

source ~/.bashrc 后 即可使用简化动gr  gerp 搜索字段  文件类型 如:

gr langxw h

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值