0

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

nishan
  • 141

1 Answers1

4

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
Mel
  • 458
  • 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" :) – u1686_grawity May 10 '11 at 20:39