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

前端 未结 15 1618
情深已故
情深已故 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 08:09

    Someone here has just suggested sudoing tee:

    sudo ls -hal /root/ | sudo tee /root/test.out > /dev/null
    

    This could also be used to redirect any command, to a directory that you do not have access to. It works because the tee program is effectively an "echo to a file" program, and the redirect to /dev/null is to stop it also outputting to the screen to keep it the same as the original contrived example above.

提交回复
热议问题