cat命令
CentOS
# 单次写入
cat > filename << EOF
abc
efg
hig
EOF
# 追加写入
cat >> filename << EOF
ABC
DEF
GHI
EOFUbuntu
Ubuntu因为权限不一样,无法直接以root运行,要将其套在bash中执行
sudo bash -c 'cat << EOF > /PATH/FILENAME
#/bin/bash
echo "messages"
EOF'Ubuntu系统使用cat命令添加服务到systemd
sudo bash -c 'cat << EOF > /lib/systemd/system/node_exporter.service
[Unit]
Description=node_exporter Daemon
[Service]
ExecStart=/usr/bin/node_exporter --web.listen-address=0.0.0.0:9100
User=root
Restart=on-failure
RestartSec=5s
[Install]
WantedBy=multi-user.target
EOF'示例
# 显示所有内容并显示行号(行号包括空行)
cat -n file
# 显示所有内容并显示行号(行号不包括空行)
cat -b file最后更新于