2015年(68)
分类: 系统运维
2015-08-31 19:32:45
linux的history命令可以显示过去在系统上使用过的命令,默认是1000条。如:
root@cfserver ~]# history
1 Vi README
2 cat README
3 perl Makefile.PL
4 perl
5 cpan
6 ls
7 cd
。。。 略 。。。
如果想知道命令是何时执行的,那么加上环境变量HISTTIMEFORMAT就可以:如
1)某个用户
echo "HISTTIMEFORMAT=\"%Y-%m-%d %H:%M:%S \" >> /home/user01/.bash_profile
2) 所有用户
echo "HISTTIMEFORMAT=\"%Y-%m-%d %H:%M:%S \" >> /etc/profile
root@cfserver ~]# history
982 2012-12-06 17:04:05 export HISTTIMEFORMAT="%Y-%m-%d %H:%M:%S "
983 2012-12-06 17:04:07 history |less
984 2012-12-06 17:04:27 export HISTTIMEFORMAT="%Y-%m-%d %H:%M:%S "
985 2012-12-06 17:04:29 history |less
986 2012-12-06 17:04:38 ls
987 2012-12-10 09:36:52 su - oracle
988 2012-12-07 09:43:28 histroy |less
989 2012-12-07 09:43:41 history|less
990 2012-12-07 09:43:49 ls
991 2012-12-07 09:43:59 cat ~/.bash_profile
992 2012-12-07 09:44:13 echo $HISTTIMEFORMAT
993 2012-12-07 09:44:23 source ~/.bash_profile
994 2012-12-07 09:44:25 echo $HISTTIMEFORMAT
995 2012-12-07 09:44:57 vi /etc/profile
996 2012-12-07 09:46:16 history|less
997 2012-12-07 09:46:38 cat /etc/profile
998 2012-12-07 09:46:53 vi .bash_profile
999 2012-12-07 09:47:04 history|less
1000 2012-12-07 09:47:37 vi .bash_profile
1001 2012-12-07 11:50:00 su - oracle
1002 2012-12-10 09:37:00 history |less
1003 2012-12-10 09:37:17 su - oracle
1004 2012-12-10 09:45:39 cat /etc/profile
1005 2012-12-10 09:47:57 history |less
1006 2012-12-10 09:48:07 history
同时可以加大保存历史命令的条数:
echo "export HISTSIZE=5000" >> /etc/profile