[Linux] Use find to search for filename patterns

Learn how to use find to identify filenames matching specified patterns. We'll use find to identify all .jsx files in a directory, or all test files in a directory.

find . -name "*jsx" // find filename with jsx in current folder
find examples/ -name "*Spec.js"  // find filename with spec.js in examples folder

 

Learn to use the xargs Unix command to combine find and grep. First we can use find to identify which files we want to search; then we can use xargs to tell grep which files to search through.

find examples -name "*spce.js"

After we get all the filename then we want to seach for "describe" for each file:

find examples -name "*spce.js" | xargs grep describe

It is the same as:

grep -r --include="*spec.js" "describe" examples/  

 

posted @ 2017-04-18 19:52  Zhentiw  阅读(310)  评论(0编辑  收藏  举报