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?
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 prependsudo
totee
.Another way to obtain the desired result, mantaining the redirection, is to move the redirection to a subshell executed by root, through
sudo
:Lastly, you can enter a root shell in various ways, and you remain root until you
exit
explicitly that shell:For more information see the manuale pages of
sudo
,su
and of course ofbash
.Instead of creating a cronjob for setting values as described by @Seppo Erviälä, you can make use of the configuration files of
procps
andsysfsutils
./proc/sys
Values for
/proc/sys
can be set in the file/etc/sysctl.conf
. To makeecho 1500 > /proc/sys/vm/dirty_writeback_centisecs
persistent, add a line with:To load the changes in
/etc/sysctl.conf
to the current session, run:/sys
For setting values in
/sys
the packagesysfsutils
needs to be installed. The configuration file is located at/etc/sysfs.conf
. To makeecho 1 > /sys/module/snd_hda_intel/parameters/power_save
persistent, add a line with:To apply the values in
/etc/sysfs.conf
to the current session, run:Do a
sudo -s
or asudo su
first:From a script:
Best practice would be to ussue the
sudo -s
before activating the script (hence the #).EDIT: See answer by @Lekensteyn for more proper way to edit
/proc/sys
and/sys
defaults.Running these suggestions from command line will only enable them for your current session and they will reset to defaults after a reboot. If you want to enable these suggestions each time your system starts you should make them into a script:
You can place this script somewhere convinient eg.
/root/power_save.sh
.Then you want to make sure it runs with root privileges each time your system starts. This can be done with
sudo crontab -e
which opens list of time based tasks for root. Add line:Don't forget to make your script executable:
This way these power saving options will be enabled for all users, even before login, and no password is needed to authorize them each time.