Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Possible Duplicate:
sudo permission denied but su grants permission

I am trying to echo a new value into a file using following command

  sudo echo 4096 > /proc/sys/fs/file-max

The error coming is permission denied.But when I do the same thing as a root user I am successful.Can I know the reason why it happens or we can say that sudo doesnt pass through the ">" operator

share|improve this question

marked as duplicate by Michael Mrozek May 10 '11 at 21:01

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

add comment

1 Answer

sudo does not pass through the > operator because it never sees it. The shell interprets the > character and sudo only sees echo 4096. This means that the shell as your user id tries to open /proc/sys/fs/file-max and thus fails.

Work arounds:

% echo 4096 | sudo dd of=/proc/sys/fs/file-max
% sudoedit /proc/sys/fs/file-max
share|improve this answer
    
Mel's right on the thing about sudo not seeing the redirect, but I'd use tee, not dd, since mistakes with dd...well, there's a reason they call it disk destroyer! echo 4096 | sudo tee /proc/sys/fs/file-max –  maco May 10 '11 at 19:06
    
@maco There's absolutely no difference whether you use dd or tee for this, as long as you don't accidentially mistype "/dev/sda1" instead of "/proc/sys/fs/file-max" :) –  grawity May 10 '11 at 20:39
    
@MeI thanks a lot –  nishan May 11 '11 at 5:28
add comment

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