portableliner.blogg.se

Sudo cat tee
Sudo cat tee













Ask Question Asked 8 years, 9 months ago.

sudo cat tee

Sudo cat tee how to#

You could try running the whole command in a sudo subshell, like :w sudo sh -c 'cat > yams.txt', but that wont work either, because in the subshell, is nil youll blank out the contents of your file. How to bash cat or tee into a file, with sudo, with EOF, and with silent output. In that case, sudo is applied to cat, but not to >, so it is not allowed. If we want to execute such a command only once quickly, we can use sudo bash -c “Command > file” to execute the command with redirection in a sub-shell so that the root user performs both the command and the redirection: kent$ sudo bash -c 'echo "Linux is awesome! - (sub-shell)" > /opt/output. at 8:13 65 bjarkef - no, that doesnt work. However, it can be inconvenient if we always have to create shell script files for commands with redirections. Next, let’s empty the /opt/output.txt file and test our myScript.sh: kent$ sudo. 6 Answers Sorted by: 141 You can invoke a new shell as root: sudo sh -c 'echo clockhctosys\'YES\' > /etc/conf.d/hwclock' You could also just elevate a process to write to the file: sudo tee -a /etc/conf.

sudo cat tee

Now is the filename associated with the buffer So :w sudo tee will pipe the contents of the buffer through sudo tee FILENAME. So you can do, for example :w cat and it will pipe the buffer through cat. If we can turn the command and redirection into a single command, we can execute it with sudo so that the redirection gets done by root.įollowing this idea, we can create a simple shell script file containing our echo command: kent$ cat myScript.shĮcho "Linux is awesome! - (shell script)" > /opt/output.txt 3 Answers Sorted by: 42 The structure :w cmd means 'write the current buffer piped through command'.













Sudo cat tee