When you run the find command on files you don't have permissions for, you get annoying "Permission denied" errors which clutter the output.

Wikipedia suggests the following fix:

If you're doing this as a user other than root, you might want to ignore permission denied (and any other) errors. Since errors are printed to stderr, they can be suppressed by redirecting the output to /dev/null. The following example shows how to do this in the bash shell:

find / -name "myfile" -type f -print 2>/dev/null 

I know I can prepend things to a command, so I can alias ll to, for example, ls -lah. Can I set up an alias in .bash_profile to append 2>/dev/null to the end of any find command?

  • Copy / Paste: echo "find / -name \$1 -type f -print 2>/dev/null" >/sbin/find1 chmod 777 /sbin/find1 – Alan Nov 10 '16 at 22:49

What I would recommend here is to create a script with the line above suggested by Wikipedia. I would then set this script to to be executable with chmod. Place this script in your home directory or any directory in your $PATH variable or add a directory your create wherever with your custom scripts to your PATH variable. Then you can just type the script wherever you want such as "myfind"

If you set your PATH variable correctly, you could even name your script "find" since the shell will execute the first instance it will find. To ensure you are using the "right" "find" use the command "which".

Let me know if you need any more clarification after doing some more research man page reading on your own.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.