Redirecting stderr problem

% ls -ld /usr /foo
ls: /foo: No such file or directory
drwxr-xr-x  14 root  wheel  512 May 18 02:49 /usr
% ls -ld /usr /foo 1>/dev/null/
/dev/null/: Not a directory.
% ls -ld /usr /foo 2>/dev/null/
/dev/null/: Not a directory.

^^Why why why doesn't this work for me. Furthermore, where is stdout on the last?

I'm trying to prevent 'find' from barfing the permission denied errors if anybody has experienced that. Wondering if I'm doing something wrong or how to further examine stderr's config on the server.

Side note: Please forgive if this answer is already posted as I've tried searching here and google with no luck. Thanks in advance for your 0.:stuck_out_tongue:

ls -ld /usr /foo 2>/dev/null without the final /

Sorry but this did't work for me..

> ls -ld /usr 
drwxr-xr-x  14 root  wheel  512 Dec 21  2007 /usr
> ls -ld /usr /foo 2>/dev/null
ls: /foo: No such file or directory
ls: 2: No such file or directory

So again, why is it that redirecting stdout works fine but not stderr? Stdout dosesn't seem to function when stderr fails?

Ls recognizes stdout but not stderr and I'm wondering how is that I can view what stderr is tagged to because to me it's obvious it's not the default '2'. Please help.

What is your operating system?
What does the following give?
ls -lrt /dev/null

Check if this works?
ls -ld /usr /foo 2>/directory_where_u_have_permissions_to_write/err.txt

Either you are using a csh derivative which doesn't understand the 2> redirection, or you mistyped it. In csh the redirection syntax is different. What happened in the last case was that the regular output was redirected to /dev/null and the error messages were not.

Thanks ppl for the quick reply.

Sudhamacs, you answered before I got a chance to post the version but here is the information you requested..

je# uname -srp
FreeBSD 6.2-RELEASE i386
je# 

Don't think that permissions is the issue here since ls isn't recognizing '2' as a valid operator. Hence ls with the d switch will fail.

Another note i should add is that when i hit up (history) i find that the system executes with a space.

ls -ld /usr /foo 1>/dev/null/
.. works on they system as ..
ls -ld /usr /foo 1 > /dev/null/

^^Not sure if this is relevant or not. Also, here's some additional information..

je# ls -l /dev/null
crw-rw-rw-  1 root  wheel    0,   6 Aug 28 14:35 /dev/null
je# ls -l /dev/st* /dev/fd
lrwxr-xr-x  1 root  wheel  4 Dec 31  1969 /dev/stderr -> fd/2
lrwxr-xr-x  1 root  wheel  4 Dec 31  1969 /dev/stdin -> fd/0
lrwxr-xr-x  1 root  wheel  4 Dec 31  1969 /dev/stdout -> fd/1

/dev/fd:
total 0
crw-rw-rw-  1 root  wheel    0,  18 Jul 27 21:37 0
crw-rw-rw-  1 root  wheel    0,  20 Jul 27 21:37 1
crw-rw-rw-  1 root  wheel    0,  22 Jul 27 21:37 2
je# 

The % prompt is often indicative of csh, what does echo $SHELL say?

Thanks ppl for the quick reply.

Sudhamacs, you answered before I got a chance to post the version but here is the information you requested..

je# uname -srp
FreeBSD 6.2-RELEASE i386
je# 

Don't think that permissions is the issue here since the issue is ls isn't recognizing '2' as a valid operator. Hence ls with the d switch will fail.

Another note i should add is that when i hit up (history) i find that the system executes with a space.

ls -ld /usr /foo 1>/dev/null/
.. works on they system as ..
ls -ld /usr /foo 1 > /dev/null/

^^Not sure if this is relevant or not. Also, here's some additional information..

je# ls -l /dev/null
crw-rw-rw-  1 root  wheel    0,   6 Aug 28 14:35 /dev/null
je# ls -l /dev/st* /dev/fd
lrwxr-xr-x  1 root  wheel  4 Dec 31  1969 /dev/stderr -> fd/2
lrwxr-xr-x  1 root  wheel  4 Dec 31  1969 /dev/stdin -> fd/0
lrwxr-xr-x  1 root  wheel  4 Dec 31  1969 /dev/stdout -> fd/1

/dev/fd:
total 0
crw-rw-rw-  1 root  wheel    0,  18 Jul 27 21:37 0
crw-rw-rw-  1 root  wheel    0,  20 Jul 27 21:37 1
crw-rw-rw-  1 root  wheel    0,  22 Jul 27 21:37 2
je#