Matching filename in ls (bash)

I'm not sure why you're using [[:digit:]] rather than [0-9]; are you concerted the file names might contain other kinds of digits?

Most of the other answers are good, but a quick-and-dirty solution is:

ls tcpdump-*[0-9]

It works for the particular set of files you have, but it would also match file names like tcpdump-FOO7.

In a general-purpose script, it's worth the effort to match exactly the pattern you want. In a one-short interactive shell command, sloppy shortcuts that just happen to work for the current situation can be useful.


One needs to turn on extended glob functionality of bash to be able to use the advanced pattern matching.

$ ls
tcpdump-12  tcpdump-12.delay  tcpdump-24  tcpdump-24.delay
$ shopt -s extglob
$ ls tcpdump-+([[:digit:]])
tcpdump-12  tcpdump-24

If you're sure that all the unwanted files end with '.delay' you can do this:

ls --ignore '*.delay'

Tags:

Regex

Bash