1830978 Members
1942 Online
110018 Solutions
New Discussion

Simple ? ls problem

 
SOLVED
Go to solution
Jeff Picton
Regular Advisor

Simple ? ls problem

Hi all

Can anyone tell me how to get a list of files EXCEPT the ones with a specific extension, eg .tar ?
6 REPLIES 6
Peter Leddy_1
Esteemed Contributor
Solution

Re: Simple ? ls problem

Hi,

Not sure if there is an option to do this with ls but you could use ls | grep -v ".tar" and this would give you the same result.

HTH,

Peter
Muthukumar_5
Honored Contributor

Re: Simple ? ls problem

Yes. we can do it with grep and ls as,

ls | grep -v ".tar$"

We can do recurvisely in sub-dir too with -F option of ls too.

We can add two extension's with -E as,

ls | grep -Ev ".gz$|.tar$"
Easy to suggest when don't know about the problem!
ramkumar
Valued Contributor

Re: Simple ? ls problem

hi you can't do it with ls command but with find command you can do .


try to go thru the man page .
Laurent Menase
Honored Contributor

Re: Simple ? ls problem

Hi Jeff,

find . -type f \( ! -name \*.tar \)
Franky_1
Respected Contributor

Re: Simple ? ls problem

Hi,

use

find ! -name "*. -print

eg

find . ! -name "*.tar" -print (or -exec ls -l {} \;)

Regards

Franky
Don't worry be happy
Peter Nikitka
Honored Contributor

Re: Simple ? ls problem

You can do this in a ksh (try it in a posix shell!):

ls !(*.tar)

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"