Sunday, 24 June 2018

(Ubuntu/Linux)"find" command gives different results based on quotation marks


I was using


find -iname *prib*

and getting only one result "./prib09jack.pdf" with


find -iname "*prib*" 

I get many more results that I was looking for such as


./Dir1/PRIB09/prib09jackTFF1.pdf

and many more, but why did it matter that the quotation marks were around "prib"?


Best.



Answer



If there is a file (or files) matching *prib* in the current directory when the find command is run, the shell will expand the wildcard to match the file name(s) first before handing the arguments to find, and result in a different command being run than the user expects.


For example,


$ ls foo*
foobar

$ find -iname foo*
./foobar

$ find -iname "foo*"
./foobar
./dir/foobz
./dir2/fooblat

In short, Quotes delay wildcard interpretation for the find command to perform. Lack of quotes expands immediately.


No comments:

Post a Comment

Where does Skype save my contact's avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...