如果.bash_history中 包含timestamp,将很难阅读,下面Python 3脚本可翻译.bash_history
#! /usr/bin/env python3 import re import sys import time if __name__ == '__main__': pattern = re.compile(br'^#(\d+)$') out = sys.stdout.buffer for pathname in sys.argv[1:]: with open(pathname, 'rb') as f: for line in f: timestamp = 0 while line.startswith(b'#'): match = pattern.match(line) if match: timestamp, = map(int, match.groups()) line = next(f) out.write(time.strftime('%F %T ', time.localtime(timestamp)).encode('ascii')) out.write(line)
评论