On 13/02/2010, at 8:42 AM, Lucas Parry wrote:
why involve xargs at all?
find -type f -name '*.rb' -exec cat {} \;

Because this forks and execs 'cat' for every single file,
which can be a lot slower.

Find also scans all your .git/.svn directories etc, which
means you get a lot of false hits on a grep. I use two
small shell scripts in my ~/bin directory:

==> /Users/cjh/bin/files0 <==
find "$...@-.}" -type f \( -path \*.git\* -prune -o -path \*.svn\* - prune -o -path \*.swp -prune -o -print \) |
sort | tr '\n' '\0'

==> /Users/cjh/bin/grep0 <==
xargs -0 egrep "$@"

The find script sorts the filenames (something find doesn't do),
but also handles files with spaces in the names.

The use of quotes $@ means you can pass any additional
arguments, even ones with quoted spaces in them.

Typical usage:

files0 app/models | grep0 'Thing to find'

--
Clifford Heath.

--
You received this message because you are subscribed to the Google Groups "Ruby or 
Rails Oceania" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rails-oceania?hl=en.

Reply via email to