sudo 중 리다이렉션을 하면 리다이렉션부터 루트 권한을 벗어납니다.
sudo command > outputfile아래는 실제 결과입니다.
<>-root—<>—--user-—<>
[mirashi@localhost ~]$ sudo date > output분명 실행은 sudo로 했지만 리다이렉션으로 생성된 결과물의 소유자는 root가 아닌 sudo를 실행한 유저 계정인 것을 볼 수 있습니다. 이에 대한 해결책은 > 대신 'sudo tee'를, >> 대신 'sudo tee -a'를 사용하는 것입니다. 아래처럼 말이죠.
[mirashi@localhost ~]$ ls -al output
-rw-rw-r-- 1 mirashi mirashi 29 Jun 21 13:08 output
[mirashi@localhost ~]$ sudo date | sudo tee output
Fri Jun 21 13:14:25 KST 2013
[mirashi@localhost ~]$ ls -al output
-rw-r--r-- 1 root root 29 Jun 21 13:14 output