mlzboy
mlzboy

Reputation: 14701

how to grep .txt .tar.gz .py file once

i can use

ls|grep \.py$

to list all ends with .py file,but it's seems hard for me to grep all .py & .txt & .tar.gz file once

any one could give me a hand

Upvotes: 0

Views: 727

Answers (2)

ghostdog74
ghostdog74

Reputation: 342649

No need external commands. Use the shell(bash/ksh)

shopt -s nullglob
for file in *.{txt,tar,gz,py}
do
  echo "$file"
done

Upvotes: 1

kennytm
kennytm

Reputation: 523514

ls | grep -E '\.(py|txt|tar\.gz)$'

Upvotes: 2

Related Questions