tags:

views:

1315

answers:

3

I need to list all files whose names start with 'SomeLongString'. But the case of 'SomeLongString' can vary. How?

I am using zsh, but a bash solution is also welcome.

+1  A: 

Depending on how deep you want to have this listing, find offers quite a lot in this regard:

find . -iname 'SomeLongString*' -maxdepth 1

This will only give you the files in the current directory. Important here is the -iname parameter instead of -name.

Horst Gutmann
+5  A: 

bash:

shopt -s nocaseglob
Jacek Szymański
Thanks. I was hoping there was a way to specify it as part of the glob itself. The zsh manual mentions something like it but I was not able to figure it out.
Vulcan Eager
+6  A: 

ZSH:

$ unsetopt CASE_GLOB

Or, if you don't want to enable case-insensitive globbing in general, you can activate it for only the varying part:

$ print -l (#i)(somelongstring)*

This will match any file that starts with "somelongstring" (in any combination of lower/upper case). The case-insensitive flag applies for everything between the parentheses and can be used multiple times. Read the manual zshexpn(1) for more information.

UPDATE Almost forgot, you have to enable extendend globbing for this to work:

setopt extendedglob
jkramer
BTW, I had to setopt EXTENDED_GLOB for it to work.
Vulcan Eager