Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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

1 Answer 1

up vote 6 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.