Find the answer to your Linux question:
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 ...
  1. #1
    Linux Newbie Sangal-Arun's Avatar
    Join Date
    May 2006
    Location
    Gurgaon, India + Denver Colorado USA
    Posts
    101

    Question 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]$
    Brgds,

    ARUN SANGAL
    SCM: 1- 720 251 9962
    Email: sangal.ak04@gmail.com
    Email: sangal_ak04@yahoo.com

  2. #2
    Just 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.

  3. #3
    Linux Newbie Sangal-Arun's Avatar
    Join Date
    May 2006
    Location
    Gurgaon, India + Denver Colorado USA
    Posts
    101
    But, I want to search only few files or a single file amoung all others which can be more than 1,00,000 in some softwares. In that case, "find ." command will take much time. Thanks.


    Quote Originally Posted by Ben Cotton View Post
    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.
    Brgds,

    ARUN SANGAL
    SCM: 1- 720 251 9962
    Email: sangal.ak04@gmail.com
    Email: sangal_ak04@yahoo.com

  4. #4
    drl
    drl is offline
    Linux Engineer drl's Avatar
    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, drl
    Welcome - 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 )

  5. #5
    scm
    scm is offline
    Linux Engineer
    Join Date
    Feb 2005
    Posts
    1,044
    Quote Originally Posted by Sangal-Arun View Post
    Why we enclose a filename/pattern in double quotes " , " in find command with -name parameter, but not in ls command?
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...