Why I can't grep find? Only helps grepping cat of find. As I see program grep could see some context in which every command runs. But it's counterintuitive for a newbie like me. When given with argument grep can search files , but when it's with pipe ( | ) - it couldn't.
By contrast, the
The simpler way to do what you want would be to use command substitution to pass the names to
To express Nicole Hamilton's command in a more concise form you can use the -exec flag to the find command.
This passes the names of the matched files to grep with the curly brackets being replaced by the filename. The '\;' is an escaped ';' this is used to signify the end of the command.
This is a comparison of different timings for running the find command. All these tests where performed against a recent snapshot of portage (http://distfiles.gentoo.org/snapshots/portage-latest.tar.bz2). I ran 'find .' and 'grep -Rni . .' before timeing these tests so I'm hoping that disk and ram caching should be simular across all tests.
Here is the timing for the two commands:
As your can see the cat method is much quicker completing in about 5% of the time of my example.
However if the find command returns too many files we run into a limit of the shell with the lenght of a single command. This will cause the command to fail.
To see this limit on your system use.
Here is find running with the same glob. Notice that it takes a very long time to complete but it does exit succesfully.
The optimal way to safley run this command is to use xargs.
Using xargs it is possible to grep through the entire portage tree (~159995 files, 724M) in just under 2 seconds.