Sample Header Ad - 728x90

limit find output AND avoid signal 13

8 votes
4 answers
5273 views
I have a directory with ~1M files and need to search for particular patterns. I know how to do it for all the files: find /path/ -exec grep -H -m 1 'pattern' \{\} \; The full output is not desired (too slow). Several first hits are OK, so I tried to limit number of the lines: find /path/ -exec grep -H -m 1 'pattern' \{\} \; | head -n 5 This results in 5 lines followed by find: `grep' terminated by signal 13 and find continues to work. This is well explained [here](https://superuser.com/a/554896/317607) . I tried quit action: find /path/ -exec grep -H -m 1 'pattern' \{\} \; -quit This outputs only the first match. Is it possible to limit find output with specific number of results (like providing an argument to quit similar to head -n)?
Asked by Andrey (840 rep)
Dec 12, 2016, 10:37 AM
Last activity: May 25, 2023, 02:43 PM