Shell代码段-log
【日志相关】
# 创建文件时,需要把变量加上引号,命令输出包含空格 DATE="$(date "+%F %T")" touch "$DATE.log" LOG_DIR="/var/log" cd $LOG_DIR || { echo "Cannot change to necessary directory." >&2 exit 1 } cat /dev/null > messages && echo "Logs cleaned up." exit 0 cat<<EOF #清空日志三种办法 1. echo " " >test.log 2. >test.log 3. cat /dev/null >test.log EOF