Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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