查找名称包含给定字符串的所有文件,并突出显示它 [英] Find all files whose names contain a given string, and highlight it

查看:180
本文介绍了查找名称包含给定字符串的所有文件,并突出显示它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现自己写这个命令很多:

find。 -iname* foo *| fgrep -ifoo



要查找名称中包含foo的所有文件和文件夹,并突出显示结果。



这不是很方便。什么是更简单的解决方案?我需要为此编写一个自定义命令吗?

解决方案

为了方便起见,您可以为此创建一个BASH函数:

  hlt(){find。 -iname'*'$ 1'*'| grep --color$ 1; } 

并称为:

  hlt foo 


I find myself writing this command a lot:

find . -iname "*foo*" | fgrep -i "foo"

To find all files and folders that have "foo" in their names, and to highlight the matching part in the results.

That's not very convenient. What would be a simpler solution? Do I need to write a custom command for this?

解决方案

For convenience you can create a BASH function for this:

hlt() { find . -iname '*'"$1"'*' | grep --color "$1"; }

and call it as:

hlt foo

这篇关于查找名称包含给定字符串的所有文件,并突出显示它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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