Exclude specific filename from shell globbing

if you are using bash

#!/bin/bash
shopt -s extglob
ls !(fubar).log

or without extglob

shopt -u extglob
for file in !(fubar).log
do
  echo "$file"
done

or

for file in *log
do
   case "$file" in
     fubar* ) continue;;
     * ) echo "do your stuff with $file";;
   esac 
done

Leave a Comment