QA Graphic

Unix Find Tips

Filter Out the Error messages

Quick UNIX tip that I recently learned:

If your a UNIX power user, chances are you done search using the find command. The search may look like this:

find / -name python - print

The problem is that you may run into a lot of noise. In particular, you search may end up with a lot of these types of entries:


find: /usr/sbin/authserver: Permission denied
find: /Library/Application Support/Apple/ParentalControls/Users: Permission denied
find: /Library/Application Support/Apple/AssetCache/Data: Permission denied
find: /Library/Application Support/ApplePushService: Permission denied
find: /Library/Application Support/com.apple.TCC: Operation not permitted
find: /Library/OSAnalytics/Preferences/Library: Permission denied
find: /Library/Caches/com.apple.iconservices.store: Permission denied
find: /Library/Caches/com.apple.aned: Operation not permitted
find: /System/Library/DirectoryServices/DefaultLocalDB/Default: Permission denied
find: /System/Library/Templates/Data/private/var/audit: Permission denied
find: /System/Library/Templates/Data/private/var/root: Permission denied
find: /System/Library/Templates/Data/private/var/lib/postfix: Permission denied
find: /System/Library/Templates/Data/private/var/db/appinstalld: Permission denied
find: /System/Library/Templates/Data/private/var/db/diskimagesiod: Permission denied
find: /System/Library/Templates/Data/private/var/db/locationd: Permission denied
find: /System/Library/Templates/Data/private/var/db/analyticsd: Permission denied
find: /System/Library/Templates/Data/private/var/db/rmd: Permission denied
find: /System/Library/Templates/Data/private/var/db/knowledgegraphd: Permission denied
find: /System/Library/Templates/Data/private/var/db/nsurlsessiond: Permission denied
find: /System/Library/Templates/Data/private/var/db/fpsd: Permission denied

The problem is that you may lose matches in all the permission issues.

## Easy fix

There's actually an easy fix. Simply redirect the error messages. Here's all you need:

find / -name boston -print 2>/dev/null

Now when you search for something you only see the matches:


$> find / -name python  -print 2>/dev/null
/usr/bin/python
/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Aliases/python
/usr/local/Cellar/ffmpeg/4.3.1_9/share/ffmpeg/python
/usr/local/Cellar/python@3.8/3.8.7/libexec/bin/python
/usr/local/Cellar/python@3.9/3.9.1_6/libexec/bin/python
/usr/share/file/magic/python
/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python