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

What is the Linux command to return all files that start with TEMP but do not end with double digits?

I think it should look something like this:

ls -l TEMP*[!0-9][!0-9]

but the results of my search are omitting some results it seems.

share|improve this question

With GNU and most modern BSDs find:

find . -maxdepth 1 -type f -name 'TEMP*' ! -name "*[0-9][0-9]"


find . ! -name . -prune  -type f -name 'TEMP*' ! -name "*[0-9][0-9]"

ksh or bash -O extglob or zsh -o kshglob:

ls -ld TEMP*@([^0-9]?|?[^0-9]) [T]EMP TEMP?
share|improve this answer
The extglob solution will miss all files which match TEMP?, as well as the file TEMP itself. – rici Jun 5 '14 at 3:58
Note that if there's no file called TEMP but one called [T]EMP, it will be listed (except with zsh which will cancel the command). – Stéphane Chazelas Jun 5 '14 at 6:31

If your shell is ksh, or bash with the extglob option (shopt -s extglob to enable), then

ls -d TEMP!(*[0-9][0-9])

should work. If you want to search recursively and globstar is enabled (set -o globstar in ksh93, shopt -s globstar in bash) then you should be able to do that as

ls -d -- **/TEMP!(*[0-9][0-9])

(note that it does not traverse hidden directories by default)

For example, if

$ ls -d -- **/TEMP*
TEMP12345  TEMP123ab  TEMPabc12  TEMPabcde  tests/TEMP12345  tests/TEMP123ab  tests/TEMPabc12  tests/TEMPabcde


$ ls -d -- **/TEMP!(*[0-9][0-9])
TEMP123ab  TEMPabcde  tests/TEMP123ab  tests/TEMPabcde

The equivalent in zsh is:

setopt extendedglob
ls -d -- **/TEMP^*[0-9][0-9]
share|improve this answer
Have you tried that? – Hauke Laging Jun 5 '14 at 1:04
Thanks, I like the extended globbing version! ls TEMP!(*[0-9][0-9]) – user70573 Jun 5 '14 at 4:28

Your idea is okay: looking for everything starting with temp and not ending with two number. Unfortunately, I think you made a syntax mistake. You should replace ! by ^. So now you are searching for files like: temp*99 and temp*!!.

share|improve this answer

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.