Noob question: redirection doesn't seem to work

Latest response

I'm learning RHEL using 6.8 and came across this exercise in my book:

"1. Open a terminal session, and make sure you are not currently logged in as root.
2. Use the command find / -name root, which starts at the root of the file system and tries to find files with the name root. Because regular users don’t have read permission on all files, this command generates lots of permission denied errors.
3. Now run the command again using redirection of STDERR. This time the command reads as follows: find / -name root > ~/find_errors.txt. You won’t see any errors now.
4. Quickly dump the contents of the file you’ve created using cat ~/find_errors.txt. As you can see, all error messages have been redirected to a text file."

Step 3 (the redirection to file) doesn't seem to work correctly. The errors still appear on screen !

When I implement step 4, I see the file contents and they contain the output, but they don't contain the errors !

How is it that everything showing is opposite to the above instructions? What am I doing wrong?

Thank you for any help.

Responses

The redirection symbol > redirects only standard output, or STDOUT. To redirect the error output (STDERR), you'll need 2>instead.

So, for your exercise step 3, the command should be:

find / -name root 2> ~/find_errors.txt

Thank you for your help and explanation, it worked as you described. Much appreciated.

Close

Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.