Your redirection is at the wrong place. Also you are grepping for "resolve.conf" not "resolv.conf"
Code:# ls -R /etc 2>/dev/null | grep resolv.conf
Why does the following simple command at the bash shell not redirect the permission denied messages?
A similar command using find does redirect the permission denied messages as expected:Code:$ ls -R /etc |grep 'resolve.conf' 2>/dev/null ls: /etc/audisp: Permission denied ls: /etc/audit: Permission denied ls: /etc/cron.d: Permission denied ls: /etc/cups/ssl: Permission denied ls: /etc/lvm/archive: Permission denied ls: /etc/lvm/backup: Permission denied ls: /etc/lvm/cache: Permission denied ls: /etc/pki/CA: Permission denied ls: /etc/racoon/certs: Permission denied ls: /etc/selinux/targeted/modules/active: Permission denied ls: /etc/selinux/targeted/modules/previous: Permission denied resolv.conf resolv.conf.predhclient
Code:$ find /etc -name 'resolv.conf' -print 2>/dev/null /etc/resolv.conf
Yes, you are correct. I asked this same question to some of my students and none of them could figure this out. I was being a little sneaky with this as I already knew the answer. I just wondered if anyone had a clue. Thank you for your response.
There are a couple of clues as to why this doesn't work. Look at the output of the first command. Clearly the errors are comming from the ls command and not the grep command as evidenced by the leading ls: part of the errors. Also if the first command is followed up with a 'echo $?' it returns an exit status of zero. So the errors did not come from the right side of the pipe or the last command in the chain.
Finally, the bash man page clearly makes a big deal out of how important the order is when dealing with redirection. But I can't get anybody to read the man page.
I'll definitely point out the resource to them but it's going to be an uphill battle for sure.