Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the most compact version of "match everything but these strings" in the shell or regex?

Tags:

regex

grep

shell

Linux: I want to list all the files in a directory and within its subdirectories, except some strings. For that, I've been using a combination of find/grep/shell globbing. For instance, I want to list all files except those in the directories

./bin
./lib
./resources

I understand this can be done as shown in this question and this other. But both versions are not solving the case "everything, but this pattern" in general terms.

It seems that it is much easier to use a conditional for filtering the results, but I wonder if there is any compact and elegant way of describing this in regexp or in the shell extended globbing.

Thanks.

like image 465
alvatar Avatar asked Dec 05 '22 06:12

alvatar


1 Answers

yourcommand | egrep -v "pattern1|pattern2|pattern3"

like image 101
flybywire Avatar answered Dec 08 '22 01:12

flybywire