I've found using the 'find' command to search for individual files that some inconsistencies occur. Eg, I wanted to search for a particular file with the word paper in its name. If I type sudo find /mnt -iname *paper* the output is:-


which is fair enough, except it wasn't what I was looking for. But if I type sudo find /mnt -iname "*paper*" the output becomes:-


Now I see the file I was searching for (the 2nd one). So why in the first case is only the last file shown as output, whereas in the second case all files including the string paper in their names are output. Why should the quotes make a difference here.


1 Answer 1


Without the quotes, the shell is getting to parse the * before find is, and it's expanding that glob (if it's able to). With the quotes, the globbing does not occur.

To demonstrate:

$ tree
├── Wallpapers
└── stuff
    ├── Newspapers
    ├── Wallflowers
    └── Wallpapers

2 directories, 3 files
$ find stuff -iname *paper*
$ find stuff -iname '*paper*'
  • 1
    Specifically: there's a file named "Wallpapers" in the current working directory, so the shell expands sudo find /mnt -iname *paper* to sudo find /mnt -iname Wallpaper. If there was no matching file in the current directory, it would've worked. If there were multiple matches, it probably would cause a find error. Jun 14, 2019 at 22:36
  • 'Wallpapers' is found in a subfolder, not current working one. It is a folder by the way, not a file. But find fails to list files elsewhere with the same string pattern within sub-folders when not using quotes. That suggests to me that I need quotes for the 'find' command to list files as well. Jun 15, 2019 at 1:51
  • @PaulBenson I'm not talking about the "Wallpapers" folder the find command found, I'm saying there's another "Wallpapers" file/folder/whatever in the directory you're in when you run the find command. That is, if you ran ls Wallpapers before running find, it would list something (not give a "No such file or directory" error). Try running cd /var/empty; sudo find /mnt -iname *paper* -- since there isn't anything named "Wallpapers" in /var/empty, this should leave the wildcard unexpanded and hence find all matches. Jun 15, 2019 at 7:47
  • @Gordon Davisson The only 'Wallpapers' result is that folder that was listed in the output for that path recursively (/mnt). There is no other file/folder with that name. I don't know why you seem to think there is. ls Wallpapers produces nothing as 'Wallpapers' also happens to be a folder in my Home folder, but it is empty, and I'm searching on a different path anyway. Jun 15, 2019 at 16:45
  • 1
    @PaulBenson The "Wallpapers" folder in your home folder is the other one I'm talking about. I know it's not where you told find to search, but that doesn't matter; when the shell sees *paper* in the argument list, it looks for matches in your current working directory (in this case, your home folder), and replaces it with the match(es). Jun 16, 2019 at 7:20

Not the answer you're looking for? Browse other questions tagged .