Search code examples
linuxbashgnu-findutils

Loop over all *.js files in a directory skipping *.spec.js files in bash script


FILES=`find . -type f -name '*.js'`
for file in $FILES
do
  # some task
done

This will loop over all *.js files but let's say there are some .spec.js files as well which I want to skip.

a.js
a.spec.js
b.js
x.spec.js
c.js

should iterate over:

a.js
b.js
c.js

Solution

  • this is the code you looking for :

    find . -type f \( -iname "*.js" -not -iname "*.spec.js" \)