find iname is being case sensitive

Can someone please tell me why iname is being case sensitive with this?

$ find /media -iname *load* 2>/dev/null
/media/Part 2/stuff/Downloads
/media/Part 1/Application Data/Mozilla/Firefox/Profiles/wnul4kj4.irc/chatzilla/downloads
/media/Part 1/Bob_5-22-2010/Application Data_5-22-2010/Mozilla/Firefox/Profiles/nkkpe9lc.default/chatzilla/downloads
/media/Part 1/Downloads
/media/Part 1/mark/New Folder/Documents/Downloads

Why is iname not being case sensitive when I use a big "L"?

$ find /media -iname *Load* 2>/dev/null
/media/Part 2/stuff/Downloads
/media/Part 1/Application Data/Mozilla/Firefox/Profiles/wnul4kj4.irc/chatzilla/downloads
/media/Part 1/Bob_5-22-2010/Application Data_5-22-2010/Mozilla/Firefox/Profiles/nkkpe9lc.default/chatzilla/downloads
/media/Part 1/Downloads
/media/Part 1/mark/New Folder/Documents/Downloads
/media/Part 1/COKE_XP_SP3_8-24-2008/I386/DMLOAD.SY_
/media/Part 1/COKE_XP_SP3_8-24-2008/I386/DMLOADER.DL_
/media/Part 1/COKE_XP_SP3_8-24-2008/I386/LOADFIX.CO_
/media/Part 1/COKE_XP_SP3_8-24-2008/I386/LOADPERF.DL_
/media/Part 1/COKE_XP_SP3_8-24-2008/I386/MIGLOAD.EX_
/media/Part 1/COKE_XP_SP3_8-24-2008/I386/OSLOADER.EX_
/media/Part 1/COKE_XP_SP3_8-24-2008/I386/OSLOADER.NT_
/media/Part 1/COKE_XP_SP3_8-24-2008/I386/UPLOADM.EX_

Is there something special about *load* ? I have used this method many times with different word and have never had this problem.

My first guess would be that in the directory you're in there's a file or directory called Downloads. With the shell expanding the wildcards, the real command line becomes

find /media -iname Downloads 2>/dev/null

(which is everything the first command found).

Try it like this:

find /media -iname '*load*' 2>/dev/null

The single quotes around the wildcards tell the shell not to expand them, but rather pass them as they are to the command.

1 Like

Yep your right.

$ ls -l
total 1888
-rw-rw-r--.  1 bob bob    4194 Aug  5 02:53 1
-rwxr--r--.  1 bob bob     406 Jul 10 07:27 ab
-rwxr--r--.  1 bob bob     406 Jul 10 07:08 ac
-rwxrwxr-x.  1 bob bob    4707 Jul  5 23:39 a.out
-rw-------.  1 bob bob   11416 Jul  7 07:57 apple
-rw-------.  1 bob bob  294268 Aug  6 23:59 boo_20110806
-rw-------.  1 bob bob  294935 Aug  7 23:59 boo_20110807
-rw-------.  1 bob bob  299096 Aug  8 23:59 boo_20110808
-rw-------.  1 bob bob  300096 Aug  9 20:33 boo_20110809
-rw-------.  1 bob bob  301564 Aug 10 23:59 boo_20110810
-rw-------.  1 bob bob  305553 Aug 11 05:11 boo_20110811
drwxrwxr-x.  9 bob bob    4096 Jun 12 16:43 btsco                                        
drwxr-xr-x.  9 bob bob    4096 Aug 11 00:50 Desktop
-rw-rw-r--.  1 bob bob     512 Aug  2 17:23 directory.cpio
-rw-rw-r--.  1 bob bob     166 Jul 20 19:36 display
-rw-rw-r--.  1 bob bob     166 Jul 20 19:36 display~
drwxr-xr-x.  2 bob bob    4096 Aug  5 05:57 Documents
drwxr-xr-x. 10 bob bob   12288 Aug 11 02:50 Downloads
-rw-rw-r--.  1 bob bob       3 Aug 11 04:44 gg
-rw-------.  1 bob root   1481 Jul 13 06:54 grub.conf
-rw-rw-r--.  1 bob bob      78 Jul  5 18:06 hello.c
drwxr-xr-x.  2 bob bob    4096 Jun  6 09:32 Music
drwxr-xr-x.  2 bob bob    4096 Jun  6 09:32 Pictures
drwxr-xr-x.  2 bob bob    4096 Jun  6 09:32 Public
-rw-rw-r--.  1 bob bob      32 Jun 11 13:34 scripts.7z
drwxr-xr-x.  2 bob bob    4096 Jun  6 09:32 Templates
-rwxrw-r--.  1 bob bob      65 Jun 18 03:11 test
drwxr-xr-x.  2 bob bob    4096 Jun 26 02:07 Videos

Does shell expansion get handled differently in find with double quotes and single quotes than other programs? I know in grep shell expansion still happens with double quotes and not with with single quotes. I learned that from fpmurphy.

http://www.unix.com/unix-advanced-expert-users/164691-grep-backslash-question.html\#post302544734

I got the same results with single quotes and double quotes. I got all of the results I expected from both of these.

find /media -iname '*load*' 2>/dev/null
find /media -iname "*load*" 2>/dev/null

Shell expansion still happens with double quotes to a certain degree, but not wildcard expansion. Variables and commands are still substituted. See the Quoting section in the man bash (Linux) man page.

You need to understand that the shell's behavior is invariant with regard to what utilities you intend to invoke. The shell does not care one bit if you are trying to use find, or grep, or ls, or... The shell's job is basically to read a line of text, process that text according to its rules (expansions, substitutions, redirections, et al), and create a process running the desired utility with the requested arguments.

The invoked utility does not know or care if it was created by a command interpreting shell. It simply processes the arguments it was passed and gets to work.

Not knowing where the shell ends and a utility it invokes begins is a huge impediment to understanding what's going on. If this line is not clear to you, in my opinion, the most beneficial thing you could do in the very near future is to spend a few hours with the command parsing section of your shell man page, until you understand it thoroughly. It will serve you very, very well. Once you get it, you can look at the most complicated stuff and work your way through it.

You'll learn the order in which the shell performs substitutions and expansions. It'll also become trivial to understand the effects of quoting. In short, any text enclosed by single quotes (aka strong quotes) is taken literally. Nothing special happens. Double quotes (aka weak quotes) bypasses only those shell expansions, substitutions, and parsing steps that could increase the number of fields (this includes field splitting on IFS characters and filename expansion). So, no matter how the text within the double quotes is modified by processing, in the end you'll always have a single field (this is why double quoted command substitutions in a for loop list are utterly pointless).

Note: There is one exception to the double quote rule: "$@" expands to multiple fields, one per positional parameter (a hack workaround to allow dealing with a list of items when there was no list type).

Also, it may help to understand the basics of the system's execve(2) system call, which is responsible for loading a new executable image, which includes passing the command line arguments and the environment.

Regards,
Alister

Or in short: The shell rearranges whatever *something* into whatever something1 something2 something3 before the program is run. The program knows nothing about it. The shell even does for most shell statements, not just programs.