Results 1 to 5 of 5
Why we enclose a filename/pattern in double quotes " , " in find command with -name parameter, but not in ls command?
Code:
[user@build]$ find . -name "1.1"
<pressed ^C ...
- 07-22-2008 #1
Why we enclose a file/pattern in "," in find but not in ls command
Why we enclose a filename/pattern in double quotes " , " in find command with -name parameter, but not in ls command?
Code:[user@build]$ find . -name "1.1" <pressed ^C here> [user@build]$ find . -name '1.1' <pressed ^C here> [user@build]$ find . -name 1.1 <pressed ^C here> [user@build]$ ls -l "1.1" -rw-rw-r-- 1 user scm 120 Jul 21 19:01 1.1 [user@build]$ ls -l '1.1' -rw-rw-r-- 1 user scm 120 Jul 21 19:01 1.1 [user@build]$ ls -l 1.1 -rw-rw-r-- 1 user scm 120 Jul 21 19:01 1.1 [user@build]$
- 07-23-2008 #2Just Joined!
- Join Date
- Sep 2007
- Location
- Lafayette, IN
- Posts
- 83
You don't need to quote the file name in your find command in this case. If you let it run long enough, you'll see it. It probably just hasn't finished working through all of your other directories yet. Try
find . | more
To get a feel for what it's doing.
- 07-24-2008 #3
- 07-24-2008 #4Linux Engineer
- Join Date
- Apr 2006
- Location
- Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
- Posts
- 1,117
Hi.
One reason to use quotes in the find command is to prevent evaluation of a filename pattern by the shell. That means any use of the meta-characters to characterize the range of names in which you are interested: * [] ? Typically, one wants the find command to consider all files in a directory tree, so find needs to process filename patterns itself.
The explanations in info find are probably better than those in man find in this regard... cheers, drlWelcome - get the most out of the forum by reading forum basics and guidelines: click here.
90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
We look forward to helping you with the challenge of the other 10%.
( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )
- 07-24-2008 #5Linux Engineer
- Join Date
- Feb 2005
- Posts
- 1,044
As has been said, you need to quote arguments if they contain characters that the shell would otherwise consider "special". In the case of find, if you let the shell pattern-match the filename (don't quote it) you'll only be asking it find the name in your current directory that exists. If there isn't a file of that pattern the specified pattern will be passed to find unchanged. You can play with echo to see the effect of quoting. Note that shell patterns are not regular expressions, for example, dot (.) matches any character in an RE while ? matches any single character in the shell; * matches any sequence of characters in the shell while it matches zero or more occurrences of the preceding character in an RE.
Learn to use quoting properly and your Linux days will be blessed.


Reply With Quote
