how to find word in all files on partition? - Linux

This is a discussion on how to find word in all files on partition? - Linux ; I am the new one in linux world, and I am looking for command which will find all files which contain word "something". Does someone has an idea? Thanks...

+ Reply to Thread
Results 1 to 4 of 4

Thread: how to find word in all files on partition?

  1. how to find word in all files on partition?

    I am the new one in linux world, and I am looking for command
    which will find all files which contain word "something".
    Does someone has an idea?

    Thanks



  2. Re: how to find word in all files on partition?

    Veritas wrote:
    > I am the new one in linux world, and I am looking for command
    > which will find all files which contain word "something".
    > Does someone has an idea?


    Yes:

    grep -r "something" /some/dir

    though, it will of course spend some time looking through all the
    gigabytes there.

    You will have problems with special files, i.e. /dev/* with the
    variant above. If you want to scan a partition, maybe this one can be
    used:

    find . -mount -type f -print0 | xargs -0 grep "something"


    --
    This signature has been virus scanned, and is probably safe to read
    Tobias Brox, 6942'N, 1857'E

  3. Re: how to find word in all files on partition?

    [Tobias Brox]
    > grep -r "something" /some/dir


    -r is "recursive", more info about it at the man pages for grep:

    man grep
    or, eventually:
    info grep

    The double quotes are not necessary in this case - but if you want to
    search for a string with spaces, you need it.

    If you want to search for "something" including the double quotes, you
    can i.e. use single qoutes:

    grep -r '"something"' /some/dir

    > You will have problems with special files, i.e. /dev/* with the
    > variant above. If you want to scan a partition, maybe this one can be
    > used:


    > find . -mount -type f -print0 | xargs -0 grep "something"


    man find
    info find

    find is an excellent tool for finding files, it can filter by size,
    access time, file name, etc.

    find .
    => find all files in the current directory

    find . -mount
    => restrict to "only this partition" ("only this mounted file
    system"). I.e., if /usr and / are on different partitions, "find
    / -mount" will not print out anything from /usr

    find . -mount -type f
    => restrict to normal files. -type d gives directories.

    find . -mount -type f -print0 | xargs -0 command
    => xargs will feed the output from find as parameters to the command.
    -print0 and -0 is needed if you have filenames with space; space
    was traditionally always a separator in unix.

    grep will then search through the files to find your string.

    --
    This signature has been virus scanned, and is probably safe to read
    Tobias Brox, 6942'N, 1857'E

  4. Re: how to find word in all files on partition?

    On Tue, 25 Oct 2005 09:42:04 +0200, Veritas wrote:
    > I am the new one in linux world, and I am looking for command
    > which will find all files which contain word "something".
    > Does someone has an idea?


    Try this
    man -k match | grep line
    then check the results with
    man first_word_from_each_resulting_line_here

    For extra points
    man man

+ Reply to Thread