Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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
file1

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
add comment

2 Answers 2

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

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

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
add comment

Your Answer

 
discard

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.