Reputation: 89
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
Reputation: 113
You can use --hide option in ls command
that is
ls --hide='pattern'
Upvotes: 1
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
Reputation: 208107
Try this:
ls -l aaa* | grep -v "expr"
Think of the "-v" as negati*v*e search.
Upvotes: 0