Avoiding ‘permission denied’ errors when running find command

Spotlight in OSX is not good for finding files on your Mac. It will return things like documents, videos, and songs, but the tool is not useful for finding things like basic text files in non-user directories. Enter the find CLI command.

nn

When find tries to enter a directory the current user does not have access to, it will return a error like find: /.Trashes: Permission denied. These error can quickly take up all the space on your terminal screen, making valid results difficult to see. One can get around this by executing find using sudo, but why elevate privilege when you don’t need to?

nn

The solution is to run the command with the -print option. Using this option, the command can be instructed to toss out all the error messages in stderr by directing them to /dev/null.

nn

An example to run a case-insensitive search for items with iTunes in their name: n$ find / -iname iTunes -print 2>/dev/null

Leave a Reply

Your email address will not be published. Required fields are marked *