Korn Shell Wildcards

Most of us working on unix would know about the shell wildcards (* and ?). These can be very useful while working with files.
For example, *.db would match any file ending with .db in the given directory:

# ls -lrt *.db
-rw-r--r-- 1 staff staff 14336 Dec 9 18:58 messages.54672.db
-rw-r--r-- 1 staff staff 23552 Dec 11 14:07 messages.76698.db
-rw-r--r-- 1 staff staff 4536320 Dec 11 22:30 messages.57286.db
-rw-r--r-- 1 staff staff 283648 Dec 11 22:52 messages.80986.db

One of the less-known feature of the wildcards is the ability to OR them:

# ls -lrt *.@(57286|80986).db
-rw-r--r-- 1 staff staff 4536320 Dec 11 22:30 messages.57286.db
-rw-r--r-- 1 staff staff 283648 Dec 11 22:52 messages.80986.db

Further, you can negate them as well:

# ls -lrt !(*.@(57286|80986)).db
-rw-r--r-- 1 staff staff 14336 Dec 9 18:58 messages.54672.db
-rw-r--r-- 1 staff staff 23552 Dec 11 14:07 messages.76698.db

Here is a quick reference of all KSH wildcards.

I find this feature really useful while working with multiple files and wish to process them, except a few.
For example, removing all the log files in a directory except the one for the active process (assuming PID is part of the file name).

Hope you find use of this in your day-to-day work!

Manuj Bhatia

Manuj Bhatia