• Visitors can check out the Forum FAQ by clicking this link. You have to register before you can post: click the REGISTER link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. View our Forum Privacy Policy.
  • Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!

Unix Find: Question for the experts

Collapse
X
  •  
  • Filter
  • Time
  • Show
Clear All
new posts

    Unix Find: Question for the experts

    Team,

    if I am in for example my filesystem on Unix
    eg:

    /home/MilanB

    is it possible to do a find, but to search for a string in all of the files in the file system ?


    Like:

    find <this string> in any files in this filesystem

    Thanks,

    Milan.

    #2
    cd <root directory to search from>
    grep "whattofind" `find .`

    Note that is the apostrophe below the escape key on most keyboards.
    Listen to my last album on Spotify

    Comment


      #3
      use -->

      man grep

      to get all the various flavours and examples, or else buy "Unix in a Nutshell" , now there's a book that has saved my ar5e more than once.

      Comment


        #4
        Can't remember the exact syntax but Google the grep command.

        Comment


          #5
          Originally posted by zeitghost
          I prefer rm * myself.

          don't forget the -r and do it from / and it may take some time ......

          Comment


            #6
            http://www.athabascau.ca/html/depts/...HOWTO/find.htm

            and see the bottom of the page.
            Behold the warranty -- the bold print giveth and the fine print taketh away.

            Comment


              #7
              Originally posted by barely_pointless
              don't forget the -r and do it from / and it may take some time ......
              God made men. Sam Colt made them equal.

              Comment


                #8
                Team,

                you're the best, the project wouldn't be the same without you.

                Thanks,

                Milan.

                Comment


                  #9
                  Originally posted by milanbenes
                  Team,

                  if I am in for example my filesystem on Unix
                  eg:

                  /home/MilanB

                  is it possible to do a find, but to search for a string in all of the files in the file system ?


                  Like:

                  find <this string> in any files in this filesystem

                  Thanks,

                  Milan.
                  not tested but off the top of my head

                  ls -R | xargs grep <string>

                  -R recursively lists subdirs; the superbly useful xargs splits input into sets of strings, not too many for the specified command to handle (otherwise "ls -R" may well return too many results for grep to swallow).

                  Edit: sorry, didn't read carefully. Do you specifically want to do a unix "find"?
                  What results do you want? List of all found strings, or just a list of files with the string? That would be grep -l (that's a lower case letter ell).


                  Note: interestingly, I described how to use grep with ls (or it could have been find) as a subsidiary tool; previous link described how to use find with grep as a subsidiary tool.

                  So much for unix's "have only one way of doing something".

                  Question: is it really true that one is subsidiary to the other, or are they coroutines?
                  Last edited by Euro-commuter; 20 July 2007, 09:25.
                  God made men. Sam Colt made them equal.

                  Comment


                    #10
                    thanks again,

                    top reward points go to SysMan's link

                    excellent

                    Milan.

                    Comment

                    Working...
                    X