이상봉
이상봉

Reputation: 89

How to print files except certain files in Shell

I can use below shell to print filename starting with aaa.

ls -l aaa*

But how can I exclude certain pattern to print using ls command or if clause ?

Suppose I want to print all files except filename that contains expr.

[FileList]

aaa.out

expr01

aexpr02

find.sh

ch.txt

Upvotes: 2

Views: 149

Answers (3)

Arun Prabhath
Arun Prabhath

Reputation: 113

You can use --hide option in ls command

that is

ls --hide='pattern'

Upvotes: 1

tripleee
tripleee

Reputation: 189948

If your shell is Bash, you can use extended globbing.

shopt -s extglob
ls !(expr)

You can turn off extended globbing again with shopt -u extglob.

Upvotes: 0

Mark Setchell
Mark Setchell

Reputation: 208107

Try this:

ls -l aaa* | grep -v "expr"

Think of the "-v" as negati*v*e search.

Upvotes: 0

Related Questions