How to match file extensions regardless of case in a bash script

Let's say I want to match an extension .abc

, but it might appear as .abc

or .abc

. How can I identify all of these .abc

file extension options .abc

?

I am currently using:

ls | grep -i .abc

but I heard that piping for grep is usually not the best idea. Is there a better way to do this?

+3


source to share


2 answers


If you are literally typing the extension, you can use character classes:

ls *.[Aa][Bb][Cc]

      



You can also use the option -iname

find

:

find -maxdepth 1 -iname '*.abc'

      

+4


source


You can use the option nocaseglob

to inline shopt

to make globs ignore the case.



$ touch foo.abc foo.ABC
$ echo *.abc
foo.abc
$ shopt -s nocaseglob
$ echo *.abc
foo.ABC foo.abc

      

+2


source







All Articles