views:

1198

answers:

4

I need to hide all "permission denied"-messages from:

find . > files_and_folders

I am experimenting when such message arises. I need to gather all folders and files, to which it does not arise. Is it possible to direct the permission levels to the files_and_folders-file? How can I hide the errors at the same time?

+6  A: 

Use:

find . 2>/dev/null > files_and_folders

This hides not just the permission denied errors, of course, but all error messages.

If you really want to keep other possible errors, such as too many hops on a symlink, but not the permission denied ones, then you'd probably have to take a flying guess that you don't have many files called 'permission denied' and try:

find . 2>&1 | grep -v 'permission denied' > files_and_folders
Jonathan Leffler
+4  A: 

Redirect standard error. For instance, if you're using bash on a unix machine, you can redirect standard error to /dev/null like this:

find . 2>/dev/null >files_and_folders
Jason Coco
A: 

Pipe stderr to /dev/null by using 2>/dev/null

find . -name '...' 2>/dev/null

Matt
+1  A: 

Those errors are printed out to the standard error output (fd 2). To filter them out, simply redirect all errors to /dev/null:

find . 2>/dev/null > some_file

or first join stderr and stdout and then grep out those specific errors:

find . 2>&1 | grep -v 'Permission denied' > some_file
viraptor