user1078719
user1078719

Reputation: 195

UNIX 'ls' command exclude wildcard

I have files a1 a2 a3 b1 b2 b3 and I need to exclude a2 and b2 from the list using ls command only.

Upvotes: 11

Views: 27699

Answers (4)

kev
kev

Reputation: 161674

Try this:

$ ls [a-b][13]
a1  a3  b1  b3

Or

$ shopt -s extglob
$ ls !(*2)
a1  a3  b1  b3

Upvotes: 7

bouzuya
bouzuya

Reputation: 301

use --ignore option

ls --ignore=[ab]2

Upvotes: 14

dash1e
dash1e

Reputation: 7807

Try with ls and grep

ls -1 | grep -viw "a2\|b2"

Pay attention after ls a put 1 (the number one) and not the letter "l". Sometimes the font make them confusing.

Upvotes: 2

Mike Samuel
Mike Samuel

Reputation: 120516

Just list the files you want:

ls a1 a3 b1 b3

Upvotes: 2

Related Questions