Find the answer to your Linux question:
Results 1 to 10 of 10
My entire server is huge so i dont wanna download all the files to search for a code in wingrep/powergrep so i am looking for a solution to do the ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Aug 2012
    Posts
    54

    Exclamation How to search a code throughout the server? (Like a wingrep)


    My entire server is huge so i dont wanna download all the files to search for a code in wingrep/powergrep so i am looking for a solution to do the same in a centos VPS server.

  2. #2
    Super Moderator Roxoff's Avatar
    Join Date
    Aug 2005
    Location
    Nottingham, England
    Posts
    3,882
    Could you ssh into the VPS and use regular grep over your web directories? You'd not be searching files over a network then, it'd be done on the VPS itself and you'd see the results in your ssh terminal.
    Linux user #126863 - see http://linuxcounter.net/

  3. #3
    Just Joined!
    Join Date
    Aug 2012
    Posts
    54
    That sounds so cool. I wish i couldnt do that but i use windows and putty to get connected to ssh. So can you give me more details on how to do it?

  4. #4
    Trusted Penguin Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    3,391
    Connect via putty.
    Use grep.
    Code:
    man grep
    You must always face the curtain with a bow.

  5. #5
    Just Joined!
    Join Date
    Aug 2012
    Posts
    54
    Quote Originally Posted by Irithori View Post
    Connect via putty.
    Use grep.
    Code:
    man grep
    Oh. I didnt know i already had a grep. Thas cool. Thank you very much.

  6. #6
    Just Joined!
    Join Date
    Aug 2012
    Posts
    54
    Could you give me an example of a command to search for like "preg_replace" throughout the entire server and show me the process and the results right away?

    There are so many options and i actually got lost in them. Tried few things but couldnt really success.

  7. #7
    Linux User Krendoshazin's Avatar
    Join Date
    Feb 2005
    Location
    London, England
    Posts
    471
    Code:
    grep -Rn preg_replace /
    This will search the entire filesystem for preg_replace. / is the directory you're searching, and in this case it's the root of the filesystem. Here's an example of searching everything under the current directory:
    Code:
    grep -Rn main .
    ./public_html/uploads/patches/binutils-2.19.1-testsuite.patch:16: main ()
    ./public_html/uploads/patches/binutils-2.19.1-testsuite.patch:20:   printf ("mainvar == %d\n", mainvar);
    ./public_html/uploads/patches/binutils-2.19.1-testsuite.patch:24:   printf ("shlib_checkfunptr2 (main_called) == %d\n",
    ./public_html/uploads/patches/binutils-2.19.1-testsuite.patch:25:         shlib_checkfunptr2 (main_called));
    ./public_html/uploads/patches/binutils-2.19.1-testsuite.patch:48:-  if (p == main_called)
    ./public_html/uploads/patches/binutils-2.19.1-testsuite.patch:52:-  printf (" main_called\n");
    ./public_html/uploads/patches/binutils-2.19.1-testsuite.patch:58:+    if (p == main_called)
    ./public_html/uploads/patches/binutils-2.19.1-testsuite.patch:62:+    printf (" main_called\n");
    As you can see it tells you what file it occurred in and on what line, which means you can go straight to the desired line.

  8. #8
    Just Joined!
    Join Date
    Aug 2012
    Posts
    54
    Perfect. Thx.

  9. #9
    Penguin of trust elija's Avatar
    Join Date
    Jul 2004
    Location
    Either at home or at work or down the pub
    Posts
    3,569
    If you are getting to may results, you can send the output to a file for further analysis by (to nick the prior example)
    Code:
    grep -Rn preg_replace / > ~/grep.txt
    which will put the output in a file called grep.txt in your home directory.
    What do we want?
    Time machines!

    When do we want 'em?
    Doesn't really matter does it!?


    The Fifth Continent

  10. #10
    Just Joined!
    Join Date
    Aug 2012
    Posts
    54
    Quote Originally Posted by elija View Post
    If you are getting to may results, you can send the output to a file for further analysis by (to nick the prior example)
    Code:
    grep -Rn preg_replace / > ~/grep.txt
    which will put the output in a file called grep.txt in your home directory.
    This is very useful. Thank you.

Posting Permissions

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