Monday, April 29, 2024
15
rated 0 times [  15] [ 0]  / answers: 1 / hits: 3513  / 1 Year ago, mon, december 12, 2022, 12:55:17

Possible Duplicate:

sudo & redirect output






These are suggestions given by powertop to save energy:



echo 1500 > /proc/sys/vm/dirty_writeback_centisecs

echo 1 > /sys/module/snd_hda_intel/parameters/power_save


However, I cannot execute them from terminal even as sudo. Ideas?


More From » command-line

 Answers
1

Your command doesn't work because the redirection > file is done by the current shell prior to the execution of the command, so before the sudo is in effect.



There is a command, called tee, that writes to a file and to stdout what it receives on its stdin: this is handy to write something to a file without redirection. If the file can be modified only by root, it is sufficient to prepend sudo to tee.



echo 1500 | sudo tee /proc/sys/vm/dirty_writeback_centisecs


Another way to obtain the desired result, mantaining the redirection, is to move the redirection to a subshell executed by root, through sudo:



sudo sh -c 'echo 1500 > /proc/sys/vm/dirty_writeback_centisecs'


Lastly, you can enter a root shell in various ways, and you remain root until you exit explicitly that shell:



sudo su
sudo -s
sudo bash


For more information see the manuale pages of sudo, su and of course of bash.


[#44477] Monday, December 12, 2022, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
lowstonnequ

Total Points: 279
Total Questions: 125
Total Answers: 123

Location: Finland
Member since Sun, Dec 5, 2021
2 Years ago
lowstonnequ questions
Wed, Oct 26, 22, 14:40, 2 Years ago
Tue, Feb 28, 23, 01:39, 1 Year ago
Wed, Dec 1, 21, 23:44, 2 Years ago
Thu, Apr 21, 22, 13:13, 2 Years ago
;