find question marks in file names

Discussion in 'macOS' started by raison, Aug 6, 2011.

  1. raison macrumors member

    Joined:
    Nov 13, 2009
    #1
    I am trying to use the find tool to look for files that contains the question mark in their names. I am using:

    Code:
    find . -name *\?* -print
    But that is displaying all the files in the current directory. What is the proper way?
     
  2. fat jez macrumors 68000

    fat jez

    Joined:
    Jun 24, 2010
    Location:
    Glasgow, UK
    #2
    the . in between your find command and -name means current working directory, which is why it's only looking there, i.e.

    . current working directory
    .. parent directory
     
  3. mfram macrumors 65816

    Joined:
    Jan 23, 2010
    Location:
    San Diego, CA USA
    #3
    You need to put single quotes around the filename part:

    Code:
    imac:~> find . -name '*\?*'
    ./bin/foo?
    
    imac:~> find . -name *\?*
    find: No match.
    The reason is because without the single quotes the shell will expand your *\?* in place which is not what you want.
     

Share This Page