How to use sudo to run complex linux commands

$ 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”.

Related Article
WordPress 3D rotating tag cloud

This 3D tag cloud is not the flash version of WP cumulus n years ago. This 3D rotating tag cloud Read more

Using wampserver tool to build local PHP + MySQL environment

No matter whether we use domestic space or foreign hosts, we prefer to go online after local debugging before setting Read more

How to install Linux system on Android phone

In our daily use of Android mobile phones, the installation of a complete Linux system will make mobile phones become Read more

How to backup your website data with Android phone

No matter what you do, backup is very necessary and important. Backup is just in case. Most of the time, Read more

Leave a Reply

Your email address will not be published. Required fields are marked *

To prove you're a person (not a spam script), type the security word shown in the picture.
Anti-spam image