Instant replay: Debugging C and C++ programs with rr
<p><pre><code>  sudo sh -c 'echo 1 >/proc/sys/kernel/perf_event_paranoid'
</code></pre>
Here’s another way of doing this:<p><pre><code>  echo 1 | sudo tee /proc/sys/kernel/perf_event_paranoid
</code></pre>
You can’t use > redirection to a different user, because that’s just a file descriptor and they don’t have a user associated with them; but pipes can run between different users like this (well, I guess it’s sudo handling the plumbing there), and so tee can run as root, receiving input from an unprivileged user and then doing what it does, writing the contents of stdin both to a file and to stdout.<p>This leads to a particularly useful trick in Vim if you edit a file you don’t have permission to write (most likely because you forgot to run `sudo vim` but now you’ve made the changes and you just want to save it, not quit and do it again as root):<p><pre><code>  :w !sudo tee %
</code></pre>
That is: “write the contents of this buffer to the stdin of a `sudo tee ‹buffer filename›` invocation”. (See also <a href="https://stackoverflow.com/questions/2600783/how-does-the-vim-write-with-sudo-trick-work" rel="nofollow">https://stackoverflow.com/questions/2600783/how-does-the-vim...</a> for more detailed explanation.)