首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >Quickly Find Content in Files

Quickly Find Content in Files

作者头像
技术小黑屋
发布于 2018-09-04 16:40:40
发布于 2018-09-04 16:40:40
6340
举报
文章被收录于专栏:技术小黑屋技术小黑屋

Although Eclipse does provide a lot of facilities for Finding content is Workspace files, it maybe less efficient for find something such as a certain package or class usage. Actually we could do it more efficient and geeky.

Now we use the classic Unix command grep.

1 2 3 4 5 6

#Grammar grep -E "word_to_search" folder_to_search -R --color=always -n #Demo grep -E "android.os.Looper" ./ -R --color=always -n .//src/com/mining/app/zxing/decoding/DecodeHandler.java:23:import android.os.Looper; .//src/com/mining/app/zxing/decoding/DecodeThread.java:24:import android.os.Looper;

Let’s take a look at the command arguments explanation.

-E, —extended-regexp Interpret pattern as an extended regular expression (i.e. force grep to behave as egrep). -R, -r, —recursive Recursively search subdirectories listed. —colour=[when, —color=[when]] Mark up the matching text with the expression stored in GREP_COLOR environment variable. The possible values of when can be never, always or auto. -n, —line-number Each output line is preceded by its relative line number in the file, starting at line 1. The line number counter is reset for each file processed.

Is this trick awesome? Save it as a bash script named quickfind.sh.

1 2

#!/bin/bash grep -E $1 . -R --color=always -n

Then let it executable and just run it.

1 2

chmod a+x quickfind.sh quickfind.sh "android.os.Looper"

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档