+ Reply to Thread
Results 1 to 6 of 6

Find and list all files containing <string>

  1. Find and list all files containing <string>

    Hi,

    Pardon my ignorance, but if I want to search all files on a disk and
    list the path/name of files containing , how would I do that in
    freebsd?

    My distro is a stripped firewall and it has no 'man' info...

    Thanks for an elegant solution on this

    /geir

  2. Re: Find and list all files containing <string>

    On 29 Mrz., 12:55, Geir wrote:
    > Hi,
    >
    > Pardon my ignorance, but if I want to search all files on a disk and
    > list the path/name of files containing , how would I do that in
    > freebsd?


    Very roughly (it will require a long time, though, depending on the
    size of the filesystem)...

    find / -type f | xargs grep -l ''

    You need more elaborate solutions if you have to consider e.g. newline
    characters as part of your filenames, or if you want to skip binary
    files, or want to handle mounted file systems specifically, or... (see
    man pages of you version of find and xargs)

    Janis

    >
    > My distro is a stripped firewall and it has no 'man' info...


    (There should be man pages available somewhere on the web.)

    >
    > Thanks for an elegant solution on this
    >
    > /geir




  3. Re: Find and list all files containing <string>

    * Janis [2007.03.29 11:39]:
    > On 29 Mrz., 12:55, Geir wrote:
    >> Pardon my ignorance, but if I want to search all files on a disk and
    >> list the path/name of files containing , how would I do that in
    >> freebsd?

    >
    > Very roughly (it will require a long time, though, depending on the
    > size of the filesystem)...
    >
    > find / -type f | xargs grep -l ''
    >
    > You need more elaborate solutions if you have to consider e.g. newline
    > characters as part of your filenames, or if you want to skip binary
    > files, or want to handle mounted file systems specifically, or... (see
    > man pages of you version of find and xargs)


    Is it me or would

    find / -type f -exec grep -l '' {} \+

    solve most of the file name issues (spaces, newlines, etc.)?

    It would probably not be much faster though.

    If it's an operation to be done more than once, I would
    look into 'glimpse': http://webglimpse.net

    --
    JR

  4. Re: Find and list all files containing <string>

    Geir writes:

    > Hi,


    > Pardon my ignorance, but if I want to search all files on a disk and
    > list the path/name of files containing , how would I do that in
    > freebsd?


    find -type f -print | xargs grep -ls

    --
    Fußgänger sind wie das ideale Gas: Sie nehmen jeden zu Vergügung gestellten
    Verkehrsraum vollständig ein, notfalls durch intensives Torkeln.

  5. Re: Find and list all files containing <string>

    Geir writes:

    > Hi,
    >
    > Pardon my ignorance, but if I want to search all files on a disk and
    > list the path/name of files containing , how would I do that
    > in freebsd?


    If is part of the filename, (i.e. you are long looking for
    "string" inside the file contents), then

    find . -name '*string*'


    --
    Sending unsolicited commercial e-mail to this account incurs a fee of
    $500 per message, and acknowledges the legality of this contract.

  6. Re: Find and list all files containing <string>

    > Pardon my ignorance, but if I want to search all files on a disk and
    > list the path/name of files containing , how would I do that
    > in freebsd?


    If you want a multi-directory grep like function:

    find -name -exec grep {} /dev/null \;

    This will list out the actual source line containing the search string as well
    as the file where it was found.

+ Reply to Thread