Finding files not ending with specific extensions

2019-07-14 19:35发布

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.

2条回答
【Aperson】
2楼-- · 2019-07-14 20:11

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.

查看更多
三岁会撩人
3楼-- · 2019-07-14 20:18

You can use:

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

Or without regex:

find . -type f -not \( -name '*.psd' -o -name '*.xcf' \)
查看更多
登录 后发表回答