I got a Raspberry PI and, even with the root user, I got some "permission denied" using commands like when I want to access the gpio. I tried with and without sudo. sample :

# cd /sys/class/gpio/

# ls

# sudo echo 24 > export (Permission denied)

But I can create users and add them to the sudo list. I don't understand, how can it be possible ?

Thanks to answer me.

  • "sudo echo" won't work, because "echo" is internal bash command and not a program or an executable script.
    – lenik
    Oct 1, 2013 at 23:44
  • @lenik : Incorrect! Sort of. echo is a built-in, but there's also an executable (try whereis echo). However, /bin/echo foo > bar still won't work. The problem is the output redirection (>) which is done by your current non-sudo shell, to a file you don't have permissions on.
    – goldilocks
    Oct 2, 2013 at 9:15

1 Answer 1


As lenik sayed, echo is a built-in and thus cannot be used with sudo like that.

But in your case, it's the redirection (>) which cause problem (thanks goldilocks). Indeed, the redirection is also made by the shell and thus have the same restriction than the built-ins.

Instead, you should switch to root first:

$ sudo su
# echo 24 > export

Or if you don't want to switch:

$ sudo su -c 'echo 24 > export'

Or, only for writing in a file:

$ echo 24 | sudo dd of=/sys/class/gpio

You can have a list of shell built-ins with the following command:

$ man builtins
  • 1
    +1 Except lenik is sort-of wrong (see my comment to the OP). There are some other ways around the problem, e.g. echo 24 | sudo dd of=/sys/class/gpio.
    – goldilocks
    Oct 2, 2013 at 9:16
  • Thanks for the clarification. I indeed didn't think about the redirection.
    – Gagaro
    Oct 2, 2013 at 9:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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