Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to find which files (they can have space in the filename) of a directory contains a string using only sh and system's commands (Perl is not an option).

For a few files, this command works fine:

# grep -l word *
file 1

But if I have 270k file, I obtain the following error:

#  grep -l word *
sh: /usr/bin/grep: The parameter list is too long.

In HP-UX, the xargs command doesn't have the -0 option, so I can't use this:

# find . -print0 |xargs -0 grep -l
xargs: unknown option: -0

Do you know which command I can use?

share|improve this question

You could use a variant of your find command like this:

find . -type f -exec grep -l {} \; 
share|improve this answer

If your version of HP-UX is recent enough, you can call find with the -exec … + action. This action does the same job as xargs (call a command on multiple matching files at once, without overflowing the command line length limit), but in a reliable way for any file name.

find . -type f -exec grep -l word {} +

If your version of HP-UX is too old, you might have only -exec … \; and not -exec … +. The ; version calls the command on one file at a time, which is a bit slower.

find . -type f -exec grep -l word {} \;

If your file names don't contain \"' or whitespace, then you can use xargs without the -0 option.

find . -type f -print | xargs grep -l word
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.