Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I list files with a filename ending with last character and with .txt extension ?

I have tried ls *+([[:digit:]]).txt but this is true for abc12.txt and abc2.txt.

But I need to get only abc2.txt. How can I do that?

Is there any sort form of :digit: that will do this?

share|improve this question
It should be noted pattern is only valid with extended globbing endabled: shopt -s extglob. – donothingsuccessfully Aug 4 '12 at 17:04
up vote 11 down vote accepted

How about:

ls *[!0-9][0-9].txt

The ! at the beginning of the group complements its meaning.

share|improve this answer
Thanks buddy ..:) – Web-E Aug 4 '12 at 17:13

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.