Linux 基本命令(一)--histroy 常用命令详解
2019-07-30 ? Linux下history命令用法
# history | head -10 30 rm -fr lala 31 for i in `seq 1000`; do 32 sleep 1 33 for i in `seq 1000`; do sleep 10 34 cd /home/ 35 ll 36 cd lib/ 37 ll 38 cd .. 39 ll ? 貌似达不到我们想要的效果,显示具体时间,具体命令的效果,那现在让我们一起来探索一下history命令的奥妙吧! 使用 HISTTIMEFORMAT 显示时间戳# export HISTTIMEFORMAT=‘%F %T‘ # history | more 1 2016-08-01 14:47:55ls 2 2016-08-01 14:47:55vim /etc/sudoers 3 2016-08-01 14:47:55ls 4 2016-08-01 14:47:55cd /home/ruanyang/ 5 2016-08-01 14:47:55ls 6 2016-08-01 14:47:55cd 下载 7 2016-08-01 14:47:55ls 8 2016-08-01 14:47:55cd ctags-5.8/ 备注:这个环境变量的声明只能作用于当前的bash,所以如果长久有效的话,需要将其定义到 使用 HISTSIZE 控制历史命令记录的总行数将这两行内容追加到 export HISTSIZE=100000 export HISTFILESIZE=100000 备注:如果我们想要看到更多的历史命令时,不妨使用这个变量 使用 HISTFILE 更改历史文件名称默认情况下,历史命令存放在 export HISTFILE=/.logs/history_${LOGNAME} 备注:这样可以将每个用户的历史文件清晰的使用文件名来标记,方便分析 使用 HISTCONTROL 从命令历史中剔除连续重复的条目
# export HISTCONTROL=ignoredups
# cd
# cd
# cd
我们现在来看看效果吧! # history | tail -n 5 133 2016-08-01 17:51:30history 134 2016-08-01 18:09:54export HISTCONTROL=ignoredups 135 2016-08-01 18:09:59cd 136 2016-08-01 18:10:04history 137 2016-08-01 18:22:12history | tail -n 5 三个 使用 HISTCONTROL 清除整个命令历史中的重复条目
# export HISTCONTROL=erasedups
# pwd
# cd
# ls
# pwd
# pwd
看看效果吧! # history | tail -10 100 2016-08-01 18:34:47export HISTCONTROL=erasedups 101 2016-08-01 18:34:58cd 102 2016-08-01 18:34:58ls 103 2016-08-01 18:35:07pwd 104 2016-08-01 18:35:20history | tail -10 使用 HISTCONTROL 强制 history 不记住特定的命令
$ export HISTCONTROL=ignorespace
$ ls
$ cd
$ pwd
注意,我在 $ history | tail -5 1997 more sources.list 1998 export HISTCONTROL=ignorespace 1999 ls 2000 pwd 2001 history | tail -5 使用HISTSIZE禁用history如果想禁用history,可以将HISTSIZE设置为0: $ export HISTSIZE=0 $ history 使用HISTIGNORE忽略历史中的特定命令忽略 $ export HISTIGNORE="pwd:ls:" $ pwd $ cd $ ls 看看效果吧! $ history 4 1998 export HISTIGNORE="pwd:ls:" 1999 cd 2000 history 5 快捷键-使用CTRL+R搜索历史比较简单,自己动手试一下吧! 从命令历史中执行一个指定的命令!number eg.!4 指定关键字来执行以前的命令输入!ps并回车,将执行以ps打头的命令 快速重复执行上一条命令以下四种方法,上方向键、 $ history 4 1998 export HISTIGNORE="pwd:ls:" 1999 cd 2000 history 5 2001 history 4 $ !! history 4 1998 export HISTIGNORE="pwd:ls:" 1999 cd 2000 history 5 2001 history 4 $ !-1 history 4 1998 export HISTIGNORE="pwd:ls:" 1999 cd 2000 history 5 2001 history 4 $ history 4 1998 export HISTIGNORE="pwd:ls:" 1999 cd 2000 history 5 2001 history 4 命令替换
演示: $ ls go go $ cat !$ #!!:$也可以实现 cat go #!/home/s/ops/perl/bin/perl ...... History命令语法# history [n] # history [-c] # history [-raw] histfiles 参数: Linux系统当你在shell(控制台)中输入并执行命令时,shell会自动把你的命令记录到历史列表中,一般保存在用户目录下的.bash_history文件中。默认保存1000条,你也可以更改这个值。 如果你键入 history,history会向你显示你所使用的前1000个历史命令,并且给它们编了号,你会看到一个用数字编号的列表快速从屏幕上卷过。你可能不需要查看1000个命令中的所有项目,当然你也可以加入数字来列出最近的 n 笔命令列表。 linux中history命令不仅仅让我们可以查询历史命令而已. 我们还可以利用相关的功能来帮我们执行命令。 运行特定的历史命令history会列出bash保存的所有历史命令,并且给它们编了号,我们可以使用“叹号接编号”的方式运行特定的历史命令. [[email?protected]]# [!number] [!command] [!!] 参数说明: 文章转自:https://www.cnblogs.com/cherishry/p/5886035.html (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |