Thread: linux find utilty

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    40

    linux find utilty

    to find a content in a directory ... whichever file contains it .. needs to display ..
    similar like windows utility..

    find . -name 'hi'

    it will search the filename hi in current directory...
    is there any find utility by which i can find search pattern in n number of file and it contains it will be displayed.

    Your help will be highly appreciated!
    Thanks
    Vaibhav

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,412
    Moved to Tech Board.

    You might want to research find and grep, or maybe you are just looking to use ls with suitable arguments.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    To search a single file for an instance of a string "foo":

    Code:
    grep foo <filename>
    To recursively search all files under a particular directory for a string "foo", and display the names of files which contain that string:

    Code:
    grep -Hrl foo <dir>
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  4. #4
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300

    Cool

    Quote Originally Posted by vaibhavs17 View Post
    it will search the filename hi in current directory...
    is there any find utility by which i can find search pattern in n number of file and it contains it will be displayed.

    Your help will be highly appreciated!
    Thanks
    Vaibhav
    I wrote a really nice GUI app to do (in part) exactly that -- recursive grep searches which then present all the files, with finds highlighted AND indexed!! It's great for, eg, library includes.

    TkCodex

    Unfortunately, I wrote it mostly for myself, so the configuration is sort of limited and a couple of people have been unable to figure out how it works without emailing me, although there's documentation at the site (qv "Simple Command Lookup"). Anyway, have a look, if you have a problem I'll be only too happy to explain anything. It's perl/Tk and needs no compiling.

    An example: if you want to search all of "/usr/include" and its subdirectories for a term:

    TkCodex /usr/include c,h "some_struct_def"


    And you get a nice little GUI ranking the results, which you can then use to view the files with the finds highlighted and a clickable sidebar index of all the corresponding line numbers. I use it everyday.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  5. #5
    Registered User
    Join Date
    Mar 2009
    Posts
    40
    Quote Originally Posted by brewbuck View Post
    To search a single file for an instance of a string "foo":

    Code:
    grep foo <filename>
    To recursively search all files under a particular directory for a string "foo", and display the names of files which contain that string:

    Code:
    grep -Hrl foo <dir>
    this command is really amazing. can you tell me what does -H options with grep.
    I could understand the usage of r and l option ... r used for recursive search and l used for display list of file which contains patter foo

  6. #6
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218
    Type:
    Code:
    man grep
    and you will find
    -H, --with-filename
    Print the file name for each match. This is the default when
    there is more than one file to search.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Why Linux, for the average user?
    By Hunter2 in forum A Brief History of Cprogramming.com
    Replies: 32
    Last Post: 07-07-2006, 02:36 PM
  2. Port app from Windows to Linux
    By BobS0327 in forum Linux Programming
    Replies: 12
    Last Post: 02-12-2006, 02:35 AM
  3. A Few questions about linux
    By punkrockguy318 in forum Tech Board
    Replies: 8
    Last Post: 01-14-2004, 03:06 PM
  4. Linux? Windows Xp?
    By VooDoo in forum Linux Programming
    Replies: 15
    Last Post: 07-31-2002, 08:18 AM
  5. Linux/Xp
    By Unregistered in forum A Brief History of Cprogramming.com
    Replies: 32
    Last Post: 06-17-2002, 11:34 AM