Bash – list all files with extension .log except one

bashls

I would like to list all files with extension .log except the file backup.log.

I have tried using this command:

ls *.log -I "backup.log"

But all the log files are listed, even backup.log!

How could I list all the log files except backup.log?

Best Answer

The shell expands the wildcard, so ls gets backup.log as one of the parameters.

Use an extended pattern (enabled by shopt -s extglob):

ls !(backup).log