0

Trying to create file in /opt folder with command:

sudo echo '01' > aaa

Got error -bash: aaa: Permission denied

Works fine if I create file, edit and save with vim

sudo vim aaa

Why I'm getting error while create file with one command while no error with other one?

vico
  • 4,527
  • 21
  • 58
  • 87

1 Answers1

3

The shell performs the redirection as you before sudo starts. You want:

sudo sh -c 'echo "01" > aaa'

so that the "aaa" file is created in the sudo process.

glenn jackman
  • 17,900