EvilZone

Programming and Scripting => Scripting Languages => : frog May 24, 2012, 09:11:47 PM

: bash - find text in a file on system w/o knowing file location
: frog May 24, 2012, 09:11:47 PM
This line alone will cat every file that the user has permission to read.
: (bash)

for item in $(find /* -name "*"); do cat $item; done


Now we add another loop inside of this mechanism along with a grep and some other things to find what we want.
: (bash)
for item in $(find /* -name "*")
  do
    for filtered in `cat $item | grep x`
      do
        echo "Filename: "; echo $item; echo ""; echo "Data:"; echo $filtered; echo ""; echo ""
    done
done
Change the parameters of grep inside the second 'for' loop to modify the search.

This script takes forever to run depending on the performance of your system. It also makes your terminal program shit its pants when you run it. It's just for fun, and I was thinking you could use `hexdump -C | grep x` to find certain patterns of bytes in any given file.
: Re: bash - find text in a file on system w/o knowing file location
: xzid May 25, 2012, 01:28:38 PM
:
$ grep -rn findme /
or using find/grep:

:
$ find / -exec grep -Hn findme {} \;
: Re: bash - find text in a file on system w/o knowing file location
: Kulverstukas May 25, 2012, 02:18:11 PM
Nice to see you and your one-liners again, xzid :D
: Re: bash - find text in a file on system w/o knowing file location
: frog May 25, 2012, 09:45:16 PM
That's much cleaner. I guess that's what I get for not using the man pages.