简体   繁体   中英

How to use chmod in ~/.bashrc

I would like to change the permission of a file in the /sys directory but the permissions keep reseting after reboot. I tried to add a chmod in the ~/.bashrc so the permission would change upon booting, but I get an error (operation not permited) in terminal. What would be the right way to do this ? Does the ~/.bashrc get executed as root ?

This is my command in ~/.bashrc

chmod 664 /sys/class/backlight/intel_backlight/brightness

And this is the error I get:

chmod: changing permissions of ‘/sys/class/backlight/intel_backlight/brightness’
: Operation not permitted

~/.bashrc is run as the user when the user logs in. It is not run on boot.

If you want to change the permissions on a file, you need to have permission to do so. The message is telling you that you don't have permission -- only root can do so.

The simplest way to do something custom on boot-up is to stick it in the file /etc/rc.local . This script is run by root after booting up (so on every reboot), so you can just stick your chmod command in there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM