How do I use sudo to redirect output to a location I don't have permission to write to?

前端 未结 15 1667
情深已故
情深已故 2020-11-22 07:23

I\'ve been given sudo access on one of our development RedHat linux boxes, and I seem to find myself quite often needing to redirect output to a location I don\'t normally h

15条回答
  •  佛祖请我去吃肉
    2020-11-22 07:58

    Yet another variation on the theme:

    sudo bash < /root/test.out
    EOF
    

    Or of course:

    echo 'ls -hal /root/ > /root/test.out' | sudo bash
    

    They have the (tiny) advantage that you don't need to remember any arguments to sudo or sh/bash

提交回复
热议问题