Unix: confusing use of the Tee -command

前端 未结 8 1851
野趣味
野趣味 2021-02-07 14:31

Manual states that the tee is a \"pipe fitting\"-tool. The cases [1] confuse me:

1. case

echo \"foo bar\" | sudo tee -a /path/to/some/fi         


        
8条回答
  •  北恋
    北恋 (楼主)
    2021-02-07 14:46

    tee copies stdin to stdout (like cat) and additionally writes everything to the named file. Using it this way with sudo allows one to push information into a privileged mode and - at the same time - monitor whether the right stuff went there.

    Also note, that due to the way redirection is handled in the shell the almost equivalent

    sudo echo "foo bar" > /path/to/some/file
    

    won't work, since the redirection would be done by the calling user and not by the sudo target user.

提交回复
热议问题