find -type f -print0 | xargs -0 -n 10 grep -i searchstring
to search recursively for a string. But it also gives me error messages like "permission denied". How can I avoid such error messages and only see results?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
If the error messages come from find (e.g. because there's a directory you can't traverse, redirect its errors to
find -type f -print0 2>/dev/null | …
If the error messages come from grep (e.g. because some files are unreadable), redirect its errors to
/dev/null, or pass the
-s option to tell it to ignore unreadable files.
xargs -0 grep -s -i searchstring /dev/null
There's no point in limiting the number of files passed together to
grep. But you should add
/dev/null so that
grep always sees at least two files, otherwise
grep omits the file name in its output if it has only one file argument. With GNU grep or Busybox (i.e. Linux or Cygwin), you can use the
-H option instead.