1

When using the find command from ~ or /, it is common to get errors related to access rights (Permission denied or Operation not permitted).

Running the find command with sudo removes some of these errors, but not all, and anyway running the command with elevated privileges is not an option.

So the question is: does the find command have a flag similar to the grep silent mode flag (grep -s) that would prevent these errors?


Edit:

The solution of removing all errors suggested several times on this page is not very elegant and potentially dangerous (find / 2>/dev/null).

A good solution comes from this answer https://unix.stackexchange.com/a/42842/199660. For example: find / -type f -iname "*balance*.pdf" 2>&1 | grep -v 'Operation not permitted' | grep -v 'Permission denied' | grep -v 'No such file or directory' | grep -v 'Not a directory'

Still, it would be nice that find provides a flag for this purpose.

nico
  • 1,130
  • 2
  • 12
  • 26
  • 1
    I'm not in favor of the proposed duplicate, as it suppresses _every_ error, not just the permission-related ones. That makes the result unreliable. `find` has an option `-readable`; haven't tried it myself but it sounds promising. – Ruud Helderman Sep 19 '22 at 13:24
  • 1
    There's no such thing as a "bash `find` command". `find` is not part of bash, is available without bash installed, and works the same way no matter which shell you're using or even if it's invoked without any shell at all (f/e, `subprocess.Popen(['find', '/'])` in Python). – Charles Duffy Sep 19 '22 at 13:38
  • 1
    `-readable` by itself won't help, but `! -readable -prune` appears to help. See: https://unix.stackexchange.com/questions/42841/how-to-skip-permission-denied-errors-when-running-find-in-linux – tjm3772 Sep 19 '22 at 13:44

1 Answers1

1

You can redirect them to /dev/ null using. find / 2>/dev/null

Niraj Nandane
  • 1,318
  • 1
  • 13
  • 24