Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> To locate a file by name in the current directory, find -iname something . (or similar). To find a file anywhere by name, use locate something (but bear in mind updatedb my not have indexed recently created files).

I think this will glob unless you escape the asterisks. Also on my system (debian 8) I need to put the directory to search first, or not at all:

find . -iname \something\

find -iname \something\

edit: hackernews ate all my asterisks



> I think this will glob unless you escape the asterisks.

The majority of times, this is the case. At least one exception is when the shell pattern does not match one or more files in the directory which find(1) is executed. However, this can be "surprising" so it's best practice to either use escapes or ensure interpolation is disabled via single quotes (in Bourne shell syntax).

> Also on my system (debian 8) I need to put the directory to search first...

FWIW, you can specify more than one directory if desired. The primaries will be applied to the results of each.


> The majority of times, this is the case. At least one exception is when the shell pattern does not match one or more files in the directory

Thankfully zsh has the NULLGLOB option which will do the right thing and expand to an empty list, of the zero matching files.


This depends a lot on the terminal, and my advise is to always suround the glob with quotes:

    find . -iname "*file*"
zsh will cry that nothing matches the glob if you don't. bash will expand it if something matches, or pass it as-is to the client if something does - which will give you unexpected results.


  edit: hackernews ate all my asterisks
Well that solved the mystery.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: