![]() ![]() The tee utility will have to run as root though, and tee -a will append data. The echo may be run as you ordinary user as it just produces a text string. The simplest way of doing that: echo 'clock_hctosys="YES"' | sudo tee -a /etc/conf.d/hwclock >/dev/null You will have to make sure that it's root that actually openes the file for writing. The redirection happens even before the sudo command is invoked. The command fails due to the permissions on the file redirected to. # echo 'clock_hctosys="YES"' > /etc/conf.d/hwclock Or you can give in to the dark side and run a shell as root. Or go from the sudo end and call sudoedit /etc/conf.d/hwclock. ![]() In Vim, call :w !sudo tee % to write to the opened file as root, or use the sudo.vim plugin. In Emacs, open /sudo:/etc/conf.d/hwclock. echo 'clock_hctosys="YES"' | sudo tee -a /etc/conf.d/hwclock >/dev/nullįor more complex file modifications, you can call sudo sed, sudo ed, sudo perl, …Īlternatively, use a decent editor and make it call sudo. Pass the -a option to tee to append to the destination file, otherwise the file is truncated. ![]() Then invoke sudo sh -c …: sudo sh -c 'echo clock_hctosys=\"YES\" > /etc/conf.d/hwclock'Īlternatively, to write output to a file that only root can write to, call sudo tee. Write the command a different way that doesn't use ': echo clock_hctosys=\"YES\" > /etc/conf.d/hwclock To execute this as root: echo 'clock_hctosys="YES"' > /etc/conf.d/hwclock If you express your command without single quotes, you can put it inside single quotes and execute that via an intermediate shell. ![]()
0 Comments
Leave a Reply. |