Kami Marie
Kami Marie

Reputation: 21

ls all directories that do NOT match multiples extensions

I am trying to list everything that does NOT end in .tar* or *.tgz

For example

directory1/
ls -ltr *
06062018.tar.gz
06062018.tar.tgz
06062018.tgz
06062018/
directory2/06062018.tar.gz
directory3/06062018.tar.tgz
directory4/06062018.tgz
directory5/06062018/
directory6/06062018.1/

Expecting the output to be:

0606218/
directory5/06062018/
directory6/06062018.1/

What I have researched:
RegEx - Find everything that does not contain a pattern
List all files that do not match selector (using ls)

List files not matching a pattern?
How to display list of all files not ending with .txt using ls command and regex?

What I have tried: ls -ltr * | grep -v $tar.gz

ls -ltr * !(*.tar.gz)
find ./* -maxdepth 1 ! -path "*tar.*"
find . -maxdepth 1 ! -path "[*.tar.gz|*tgz]"
ls -ltr | grep -v "[*tar*|*tgz]" 
ls -ltr */* --ignore=*.tar.gz --ignore=*tgz 
ls -ltr ./* --ignore=*.tar* --ignore=*tgz 

Upvotes: 2

Views: 32

Answers (1)

Barmar
Barmar

Reputation: 781098

Just use two ! -name patterns.

find * -maxdepth 1 ! -name '*.tar*' ! -name '*.tgz'

Upvotes: 1

Related Questions