[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: case insensitive ls listing?



Kamaraju Kusumanchi <kk288@cornell.edu> writes:

> This is one of my long standing problems. Is there a way to make the
> listing of ls case insensitive?
>
> for example if in a directory, I do
>
> ls -someoption tem
>
> it should show all the files such as
>
> tem, Tem, tEm, TEm, TeM, TEM etc...
>
> I could not find such an option in the default ls. Is there any
> enhance ls package which does this? or can the default ls be
> manifested to do this?
>
> I can always do
>
> ls [tT][eE][mM]
>
> but that is too cumbersome to type and errorprone.
>

Interesting question. Couple of observations:

(1) ls itself isn't actually involved in your problem; all it
    does is ls'ing it's command line parameters - i.e. in the
    expression 'ls *.c' the *.c glob is first expanded by the
    *shell* into the matching file names and then passed to ls
    as cmd line parms - ls does no expansion at all but takes
    it's parms 'as is'

(2) there is a nocaseglob option for bash (man bash, shopt),
    which will disable case matching for globs, i.e. pathname
    expansion; this means in an expression like *.c case will
    be turned off (i.e. matches a.c and a.C), but in situations
    where no globbing happens, like 'ls tmp', case will still matter.
    You can however enforce otherwise ineffective globbing in such
    a case with a construct like 'ls [t]mp'.

Conclusion: afaik, there's no straight, easy way to accomplish what
you want. Even when writing a wrapper script, e.g. 'myls', to make
use of the above, in a call like 'myls *.c' the (current) shell does
it's globbing first. Still, you then could apply a workaround like
outlined in (2) to each of the parms passed into the script and,
I guess, come pretty close to what you want.

Regards, Bruno.




Reply to: