redirect output with sudo #sudo #tee #linux #stdout
sudo sh -c 'ls -hal /root/ > /root/test.out'
sudo ls -hal /root/ | sudo tee /root/test.out > /dev/null
The redirect to /dev/null is needed to stop tee from outputting to the screen. To append instead of overwriting the output file, use tee -a or tee --append.