Jfind
My colleagues will keep all these find commands in a document. When they need to find certain string in a pile of .java or .jsp documents, they will copy-then-paste from Windows to UNIX terminal.
find . -name "DateUtil" -print;
find . -exec grep "DateUtil" '{}' \; -print;
find . -exec grep "import helper.notification" '{}' \; -print;
find . -exec grep "effectiveDate" '{}' \; -print;
find . -exec grep "ant" '{}' \; -print;
However, they do not know that it can be generalised to one shell function.
jfind() { find . \( -name "*.java" -o -name "*.jsp" \) -type f -exec grep -ilF "$*" {} \; }jfind will be more efficient than their corresponding find commands because
- locates only .java and .jsp files (no directory)
- uses fixed-string search (grep -F == fgrep)
- uses case-insensitive search
- suppresses normal output, returns only the file name. The scanning will stop on the first match
Labels: shell script
0 Comments:
Post a Comment
<< Home