历史命令脚本

 1  #!/bin/bash
 2 
 3 # archive linux command history files
 4 
 5  
 6 
 7 umask 077
 8 
 9 maxlines=2000
10 
11 #从当前历史命令中获取命令条数 
12 
13 lines=$(wc -l < ~/.bash_history)
14 
15 #条件:当前命令数大于定义的最大命令数
16 
17 if (($lines > $maxlines)); then
18 
19 #获取需要保存的命令行数
20 
21     cut=$(($lines - $maxlines))
22 
23 #获取需要保存的命令并追加
24 
25     head -$cut ~/.bash_history >> ~/.bash_history.sav
26 
27 #删掉已经保存的命令,并将剩余的命令输出到临时文件
28 
29     sed -e "1,${cut}d"  ~/.bash_history > ~/.bash_history.tmp
30 
31 #用临时文件替换源文件
32 
33     mv ~/.bash_history.tmp ~/.bash_history
34 
35 fi
[星空刺] |-->一颗星辰一闪即逝,支撑它的唯有方向和目的
原文地址:https://www.cnblogs.com/aaa103439/p/3672490.html