Monday, May 6, 2024
 Popular · Latest · Hot · Upcoming
26
rated 0 times [  26] [ 0]  / answers: 1 / hits: 66317  / 2 Years ago, fri, december 3, 2021, 5:37:01

I have a find looking like this:



rm -f crush-all.js
find . -type f ( -name "*.js" ! -name "*-min*" ! -name "*console*" ) | while read line
do
cat "$line" >> crush-all.js
echo >> crush-all.js
done


I'd like to add to exclude a directory called "test" in the find but I can't seem to figure out how to add "-type d" somehow. How'd I go about doing that?



Thanks!


More From » find

 Answers
0

You can use the -path option to find and combine it with the -not operator.



find . ! -path "*/test/*" -type f -name "*.js" ! -name "*-min-*" ! -name "*console*"


Please note two things




  • -path must come as the first argument

  • the pattern matches the whole filename, so -path test will not match anything, ever



By the way, I'm not sure why you are using parentheses, it doesn't make a difference. It is only used for precedence, for constructs such as ! ( -name '*bla*' -name '*foo*' ) (that is, do not find things that have both bla and foo).



A further refinement: no need to use the bash loop, you can simply do



find . ... -exec cat {} ; -exec echo ;


where ... are the other arguments to find.


[#34716] Sunday, December 5, 2021, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
eballxeye

Total Points: 370
Total Questions: 91
Total Answers: 139

Location: Suriname
Member since Sat, Jan 1, 2022
2 Years ago
eballxeye questions
Sun, Jan 8, 23, 18:23, 1 Year ago
Sun, Sep 11, 22, 23:24, 2 Years ago
Tue, Dec 14, 21, 07:15, 2 Years ago
;