2

I'm making a bash script; how do I find files not ending with specific extensions?

#!/bin/bash find . -type f -print | grep "\.\(?!psd\|xcf\).+$" 

Thank you.

1
  • What about using -not parameter of find? Commented Aug 24, 2015 at 21:39

2 Answers 2

5

You can use:

find . -regextype posix-egrep -type f ! -regex '.*\.(psd|xcf)$' 

Or without regex:

find . -type f -not \( -name '*.psd' -o -name '*.xcf' \) 
Sign up to request clarification or add additional context in comments.

Comments

1

You can use -v grep param like this:

find . -type f -print | grep -v "${NOT_PATTERN}" 

So, in your case you can use:

find . -type f -print | grep -v "\.\(psd|xcf\)$" 

Documentation

-v, --invert-match Invert the sense of matching, to select non-matching lines.

2 Comments

Really should have an anchor at the end like "\.\(psd|xcf\)$"
@dawg Thanks a lot for the comment, fixed now.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.