The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Searching through Shell

Discussion in 'General Discussion' started by codegirl42, Oct 10, 2006.

  1. codegirl42

    codegirl42 Well-Known Member

    Joined:
    Mar 9, 2006
    Messages:
    93
    Likes Received:
    0
    Trophy Points:
    6
    Is there an easy way to search the root for files with a certain prefix?

    Like....say I'm looking for a hack.... that has a file named blahblah.html

    How can i search the server for it?
     
  2. AndyReed

    AndyReed Well-Known Member
    PartnerNOC

    Joined:
    May 29, 2004
    Messages:
    2,222
    Likes Received:
    3
    Trophy Points:
    38
    Location:
    Minneapolis, MN
    Use the command grep
    To learn more about grep, run man grep at the command line. You can also google for grep, such as: http://en.wikipedia.org/wiki/Grep
     
  3. levelsupport

    levelsupport Well-Known Member

    Joined:
    Oct 7, 2006
    Messages:
    47
    Likes Received:
    0
    Trophy Points:
    6
    if you want to search in user home directories use this

    find /home/* | grep xyz
    here xyz is the name you want to search
     
  4. angelina_holy

    angelina_holy Well-Known Member

    Joined:
    Aug 6, 2006
    Messages:
    113
    Likes Received:
    0
    Trophy Points:
    16
    also


    find / -name 'blahblah.html'


    also yu can use locate command

    locate blahblah.html
     
  5. Manuel_accu

    Manuel_accu Well-Known Member

    Joined:
    Jun 19, 2005
    Messages:
    191
    Likes Received:
    0
    Trophy Points:
    16
    #cd /
    #egrep hack *

    or

    # grep hack blahblah.html
     
  6. sparek-3

    sparek-3 Well-Known Member

    Joined:
    Aug 10, 2002
    Messages:
    1,383
    Likes Received:
    23
    Trophy Points:
    38
    cPanel Access Level:
    Root Administrator
    grep is used to search the contents of a file for a strong (or the output of command if used with a pipe).

    find is used to find files on the server.

    locate is a lot like find, except it depends on an updatedb process running and indexing files on your server. If updatedb is not being run, then locate will not be useful. locate is also bound to files that were last indexed by updatedb. So if updatedb runs at 5AM and a file is added at 10AM, then if you run locate file at 2PM, the file added at 10AM will not show up.

    Basically to search for a particular file with a particular file extension, you would want to use find

    find -name \*\.html

    This will search for all .html files in the current directory and all directories underneath the current directory. You can further manage how far to search in a directory by using the -maxdepth and -mindepth options. A lot of information for find can be found in its man page man find
     
  7. dgbaker

    dgbaker Well-Known Member
    PartnerNOC

    Joined:
    Sep 20, 2002
    Messages:
    2,578
    Likes Received:
    3
    Trophy Points:
    38
    Location:
    Toronto, Ontario Canada
    cPanel Access Level:
    DataCenter Provider
    If you do have slocate installed, you can manually run `updatedb` then when it is done do `locate blah.html`
     
    #7 dgbaker, Oct 11, 2006
    Last edited: Oct 11, 2006
  8. Manuel_accu

    Manuel_accu Well-Known Member

    Joined:
    Jun 19, 2005
    Messages:
    191
    Likes Received:
    0
    Trophy Points:
    16
Loading...

Share This Page