beta.blog

macOS: Ignore “Permission Denied” errors when using find

by on Sep.06, 2023, under News

When using the find tool from the root directory, especially with sudo, we might run into “Permission denied” errors if we don’t have the necessary permissions to access certain directories or files. To suppress these error messages, we can redirect the standard error stream to /dev/null

Example

find / -name "libunwind.h" 2>/dev/null

In this command:

  • / is the directory where we want to start the search
  • libunwind.h is the file we’re going to search for
  • 2>/dev/null redirects all error messages (standard error, which is file descriptor 2) to
  • /dev/null effectively discarding them

Remember, if we think we should have permissions to a directory but are getting “Permission denied” nevertheless, we might want to run the sudo command by prefixing above command with sudo. However, we should use sudo judiciously, as it grants elevated permissions and can potentially modify or harm system-critical data.


Leave a Reply

*

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!