$ echo 12000 > /proc/sys/vm/dirty_writeback_centisecs
However, if this is done:
$ sudo echo 12000 > /proc/sys/vm/dirty_writeback_centisecs
You get a “permission denied” error.
Why? /Bin / echo is run as root, because you use sudo, but when you write the output of echo to all root files, it is still run as your own identity, not as root. The order of shell execution is that output redirection is performed before sudo.
The solution is to use a pipeline to send the entire command to sudo. There are several ways to do this, and my favorite one is:
echo "echo 12000 > /proc/sys/vm/dirty_writeback_centisecs" | sudo sh
In this way, no matter how complex the command is, you can put it before | sudo sh. in this way, it is very safe to execute sudo command. It only increases the complexity slightly, but it effectively avoids the error of “permission denied”.