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

前端 未结 15 1459
情深已故
情深已故 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

    Maybe you been given sudo access to only some programs/paths? Then there is no way to do what you want. (unless you will hack it somehow)

    If it is not the case then maybe you can write bash script:

    cat > myscript.sh
    #!/bin/sh
    ls -hal /root/ > /root/test.out 
    

    Press ctrl + d :

    chmod a+x myscript.sh
    sudo myscript.sh
    

    Hope it help.

提交回复
热议问题