I want to recursively find all directories and files inside a path but want to exclude some other directories and files that match given patterns. I then want to execute further commands on the search result, maybe
rm the result of
Suppose I want to prune entire
build directory and also prune
enhancers directory but would like to include in the search result a file with -name
xyz.js that is present at unknown depth inside the
With the command below I am able to achieve the desired result except include
xyz.js file in the search result. The command is very long.
find . -path "./node_modules" -prune -o -path "./.git*" -prune -o -path "./build" -prune -o -path "*/enhancers" -prune -o -print | grep 'xyz.js' --root |--node_modules |--public |--build |--.git |--.gitignore |--.env |--package.json |--src |--history |--store |--middleware |.. |.. |--enhancers |.. |--xyz.js
In the schematic directory structure above
|.. stands for unknown depth(level) inside the directory.
In the shown directory structure, I want to include all the files in the search result except,
- the entire
enhancersdirectory, but include
xyz.jsfile in search result
Is there a shorter way to do it? Major confusion is between regexp and glob patterns.
If I substitute
./\.git*, then also it works.
If I use more than one
*/enhancers, then also it works.
What pattern rules to search for files and directories are applicable in