HACKER Q&A
📣 thommyh

Why use double quotes in find command?


What problems I might encounter if I don't double quote the filename in find command?

Say I want to use this command

`find ~ -name test*`

in a directory. In what kind of presence of files in this directory will conflicting "shell expansion" occur?

My points: - When There is space in file name. Captain obvious!

I can't think of any other cases. Please explain.


  👤 reliefcrew Accepted Answer ✓
A somewhat obvious case is this:

   .                                                                                                              
   ├── subdir                                                                                                     
   │   └── test2.dat                                                                                              
   └── test.dat                                                                                                   

   1 directory, 2 files
If you don't use double quotes then the shell will expand test* to be test.dat and the final command will actually be:

  find . -name test.dat
...so the file named "test2.dat" in the sub-directory therefore won't be found.

Instead of using double quotes you can escape the asterisk so it won't be processed by the shell, e.g.

   find . -name test\*