是否存在不输出到stdout的等价于tee



当前正在使用以下内容,并希望删除> /dev/null部分。

cat << "EOF" | sudo tee /etc/pf.conf > /dev/null
EOF

为了参考,下面抛出一个错误。

zsh:拒绝权限:/etc/pf.anchors/local.test

sudo cat << "EOF" > /etc/pf.anchors/local.test
echo "Hello world"
EOF

您可以使用root权限启动一个新的shell并在其中重定向:

sudo sh -c 'cat > "$1"' -- /etc/pf.conf

或更短:

sudo sh -c 'cat > "$0"' /etc/pf.conf
sudo sh -c 'cat>"$0"' /etc/pf.conf

awk与重定向一起使用:

sudo awk -vf=/etc/pf.conf '{print > f}'

最新更新