变更记录

序号 录入时间 录入人 备注
1 2016-09-30 Alfred Jiang -

方案名称

Mac 系统 - 通过 Shell 脚本自动记录 Terminal 活动

关键字

Mac 系统 \ Terminal \ 终端

需求场景

  1. 自动记录 Terminal 活动以便于查找出错的地方

参考链接

  1. 系统之家 - MAC将Terminal活动记录下来的方法
  2. GitHub - fumbles/dotfiles/bin/loggerScript

详细内容

命令行方案

/usr/bin/script ~/Desktop/Terminal.log

脚本方案

编写以时间为序命名的小脚本来保存每一次对话脚本 logger.sh

#!/bin/bash
# logger.sh
# Log everything you do in Terminal.

#* Formatted date & time string.
FORMATTED_DATE=`/bin/date "+%Y-%m-%d-%H.%M.%S"`

#* Archive the previous file 
if [ -f ~/Desktop/Logs/Terminal.log ]; then
/bin/cp -f ~/Desktop/Logs/Terminal.log{,.$FORMATTED_DATE.txt}
fi 

#* Create Logs Directory
if [ ! -d "~/Desktop/Logs" ]; then
mkdir ~/Desktop/Logs
fi

#* Begin a new one 
/usr/bin/script ~/Desktop/Logs/Terminal.log

执行

sh logger.sh

效果图

(无)

备注

(无)

results matching ""

    No results matching ""