Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 24 Sep 2004 03:03:13 +0300
From:      Giorgos Keramidas <keramida@linux.gr>
To:        Juha Saarinen <juhasaarinen@gmail.com>
Cc:        freebsd-current@freebsd.org
Subject:   Re: Could ARG_MAX be increased?
Message-ID:  <20040924000313.GB27322@gothmog.gr>
In-Reply-To: <b34be84204092312336001936a@mail.gmail.com>
References:  <b34be84204092304456066b0a0@mail.gmail.com> <009301c4a173$d468de90$7890a8c0@gits.invalid> <b34be84204092312336001936a@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On 2004-09-24 07:33, Juha Saarinen <juhasaarinen@gmail.com> wrote:
>
> You can use the -exec feature of 'find' other wise -
>
> find . -type f -exec grep "something" {} /dev/null \;
>
> -- the /dev/null is, according to a friend, "to provide grep with more
> than one input file, so that includes the file name in any matches.

The friend is correct.  This is a nice trick.

xargs will construct a command line by appending one or more filenames
to what you pass.  The important part being ``one or more''.

If xargs appends one filename to an argument list of `grep foo', the
executed command is `grep foo filename', which will not list the name of
the file with every match since grep sees only 1 filename argument.

If the argument list passed to xargs is `grep foo /dev/null' though, the
executed command is `grep foo /dev/null filename'; in this case the
filenames grep sees are always at least 2, which enables printing the
filename with every match.

This is better illustrated with an example:

$ grep PS1 .bashrc
export PS1='${USER}@\h[\A]${PWD}\$ '
$ grep PS1 /dev/null .bashrc
.bashrc:export PS1='${USER}@\h[\A]${PWD}\$ '

Regards,
Giorgos



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20040924000313.GB27322>