问题
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?
回答1:
For convenience you can create a BASH function for this:
hlt() { find . -iname '*'"$1"'*' | grep --color "$1"; }
and call it as:
hlt foo
回答2:
if you're using bash take a look at Make a Bash alias that takes a parameter? for how to make "custom command" also note that grep without -i is case sensitive while -iname is not so you might be missing some mixed case hilights. On the side note fgrep should be faster than grep and probably less resource hungry :)
来源:https://stackoverflow.com/questions/33389064/find-all-files-whose-names-contain-a-given-string-and-highlight-it