<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></title> 
<link>http://jackxiang.com/index.php</link> 
<description><![CDATA[赢在IT，Playin' with IT,Focus on Killer Application,Marketing Meets Technology.]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></copyright>
<item>
<link>http://jackxiang.com/post//</link>
<title><![CDATA[[实践OK]Linux 下History（历史）命令用法 15 例，linux下用ctrl+r快速搜索history及SecureCRT历史答疑。history能保存多少命令？限制同一ID不能两人同时登录能解决SecureCRT只用一个用户登录history的问题吗？不能这么干。]]></title> 
<author>jack &lt;xdy108@126.com&gt;</author>
<category><![CDATA[WEB2.0]]></category>
<pubDate>Mon, 14 Jun 2010 03:52:56 +0000</pubDate> 
<guid>http://jackxiang.com/post//</guid> 
<description>
<![CDATA[ 
	零、linux下用ctrl+r快速搜索history命令：<br/>(1)ctrl + r输入后多按几次。<br/>(2)!?a.php?:p<br/>(3)命令少或就近的情况下还是直接按键盘上面的[上]键更有效率。<br/>linux命令行的history是一个熟知但不常用的命令，原因是要查某个命令的编号需要输入 history&#124;grep xxx ，又因为!?xxx,!xxx 属于运行即执行也不方便，ctrl+r则方便多了。<br/>ctrl+r<br/>用途：反向搜索执行过的命令。(reverse-i-search)<br/>1、ctrl+r<br/>2、fo<br/>3、ctrl+r (继续反向搜索)<br/>只需要寥寥几键。当然若仅是上几个命令还是[上]键更有效率。<br/><br/>一、<br/>问：linux 同一用户利用securecrt登陆两次, 各自执行一些命令后，再执行history看到的 结果不一样，是为什么？<br/>答：确定存在这个问题，是ssh的复用，只有通过在一个终端里使用history -w后，另一个终端才会看得到哈，或关闭terminal后会写入，这里有一个buffer，实践也证明是这样的。<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;要想看只有通过，如：root， /root/.bash_history，root用户登录可以再/root/目录下ls -a 可以看到有.bash_history文件 tail .bash_history 也可以看到你执行过的命令 你执行一些命令后linux会向.bash_history写 入你执行过的命令。<br/>除非你限定同一id不能同时登录：限制同一ID不能两人同时登录<br/>1、限制同一ID不能两人同时登录<br/><br/>2、防止终端用户两人同时用同一ID登录<br/><br/>1、限制同一ID不能两人同时登录<br/><br/>echo &quot;*&nbsp;&nbsp;hard max logins 2 &quot; &gt;&gt; /etc/security/limits.conf<br/><br/>2、防止终端用户两人同时用同一ID登录<br/><br/>echo &quot;session required pam_limits.so&quot;&nbsp;&nbsp;&gt;&gt;/etc/pam.d/login<br/>来自：http://www.sudu.cn/info/html/edu/linux/20080407/265620.html<br/><br/>入侵时目标如果是linux服务器，看切忌清理痕迹的时候别忘记history命令的记录哦<br/>　　1、修改/etc/profile将HISTSIZE=1000改成0或1<br/>　　清除用户home路径下。bash_history<br/>　　2、立即清空里的history当前历史命令的记录<br/>　　history -c<br/>　　3、bash执行命令时不是马上把命令名称写入history文件的，而是存放在内部的buffer中，等bash退出时会一并写入。<br/>　　不过，可以调用&#039;history -w&#039;命令要求bash立即更新history文件。<br/>　　history -w <br/><br/>二、相关命令：<br/>（1）共计最大保存history的条目数：<br/>[root@test ~]# echo $HISTSIZE<br/>1000<br/>（2）查看history存的最大值，最旧，写入：<br/>[root@localhost ~]# history &#124;head<br/>[root@localhost ~]# history &#124;head<br/>&nbsp;&nbsp;&nbsp;&nbsp;4&nbsp;&nbsp;cd ..<br/>&nbsp;&nbsp;&nbsp;&nbsp;5&nbsp;&nbsp;ll<br/>&nbsp;&nbsp;&nbsp;&nbsp;6&nbsp;&nbsp;cd ..<br/> (3)把history立即写入root:/root/.bash_history<br/>&nbsp;&nbsp;&nbsp;&nbsp;history -w<br/><br/>三、History（历史）命令用法 15 例<br/>如果你经常使用 Linux 命令行，那么使用 history（历史）命令可以有效地提升你的效率。本文将通过实例的方式向你介绍 history 命令的 15 个用法。<br/>使用 HISTTIMEFORMAT 显示时间戳<br/><br/>当你从命令行执行 history 命令后，通常只会显示已执行命令的序号和命令本身。如果你想要查看命令历史的时间戳，那么可以执行：<br/><br/><br/># export HISTTIMEFORMAT=&#039;%F %T &#039;<br/># history &#124; more<br/>1&nbsp;&nbsp;2008-08-05 19:02:39 service network restart<br/>2&nbsp;&nbsp;2008-08-05 19:02:39 exit<br/>3&nbsp;&nbsp;2008-08-05 19:02:39 id<br/>4&nbsp;&nbsp;2008-08-05 19:02:39 cat /etc/redhat-release<br/><br/><br/><br/>&nbsp;&nbsp; 14&nbsp;&nbsp;2013-12-06 23:24:11 curl &quot;www.baidu.com&quot; <br/>注意：这个功能只能用在当 HISTTIMEFORMAT 这个环境变量被设置之后，之后的那些新执行的 bash 命令才会被打上正确的时间戳。在此之前的所有命令，都将会显示成设置 HISTTIMEFORMAT 变量的时间。[感谢 NightOwl 读者补充]<br/><br/>使用 Ctrl+R 搜索历史<br/><br/>Ctrl+R 是我经常使用的一个快捷键。此快捷键让你对命令历史进行搜索，对于想要重复执行某个命令的时候非常有用。当找到命令后，通常再按回车键就可以执行该命令。如果想对找到的命令进行调整后再执行，则可以按一下左或右方向键。<br/><br/><br/># [Press Ctrl+R from the command prompt, which will display the reverse-i-search prompt]<br/>(reverse-i-search)`red‘: cat /etc/redhat-release<br/>[Note: Press enter when you see your command, which will execute the command from the history]<br/># cat /etc/redhat-release<br/>Fedora release 9 (Sulphur)<br/><br/>快速重复执行上一条命令<br/><br/>有 4 种方法可以重复执行上一条命令：<br/><br/>1.使用上方向键，并回车执行。<br/>2.按 !! 并回车执行。<br/>3.输入 !-1 并回车执行。<br/>4.按 Ctrl+P 并回车执行。<br/>从命令历史中执行一个指定的命令<br/><br/>在下面的例子中，如果你想重复执行第 4 条命令，那么可以执行 !4：<br/><br/><br/># history &#124; more<br/>1&nbsp;&nbsp;service network restart<br/>2&nbsp;&nbsp;exit<br/>3&nbsp;&nbsp;id<br/>4&nbsp;&nbsp;cat /etc/redhat-release<br/># !4<br/>cat /etc/redhat-release<br/>Fedora release 9 (Sulphur)<br/><br/>通过指定关键字来执行以前的命令<br/><br/>在下面的例子，输入 !ps 并回车，将执行以 ps 打头的命令：<br/><br/><br/># !ps<br/>ps aux &#124; grep yp<br/>root&nbsp;&nbsp;&nbsp;&nbsp; 16947&nbsp;&nbsp;0.0&nbsp;&nbsp;0.1&nbsp;&nbsp;36516&nbsp;&nbsp;1264 ?&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Sl&nbsp;&nbsp; 13:10&nbsp;&nbsp; 0:00 ypbind<br/>root&nbsp;&nbsp;&nbsp;&nbsp; 17503&nbsp;&nbsp;0.0&nbsp;&nbsp;0.0&nbsp;&nbsp; 4124&nbsp;&nbsp; 740 pts/0&nbsp;&nbsp;&nbsp;&nbsp;S+&nbsp;&nbsp; 19:19&nbsp;&nbsp; 0:00 grep yp<br/><br/>使用 HISTSIZE 控制历史命令记录的总行数<br/><br/>将下面两行内容追加到 .bash_profile 文件并重新登录 bash shell，命令历史的记录数将变成 450 条：<br/><br/><br/># vi ~/.bash_profile<br/>HISTSIZE=450<br/>HISTFILESIZE=450<br/><br/>使用 HISTFILE 更改历史文件名称<br/><br/>默认情况下，命令历史存储在 ~/.bashhistory 文件中。添加下列内容到 .bashprofile 文件并重新登录 bash shell，将使用 .commandline_warrior 来存储命令历史：<br/><br/><br/># vi ~/.bash_profile<br/>HISTFILE=/root/.commandline_warrior<br/><br/>使用 HISTCONTROL 从命令历史中剔除连续重复的条目<br/><br/>在下面的例子中，pwd 命令被连续执行了三次。执行 history 后你会看到三条重复的条目。要剔除这些重复的条目，你可以将 HISTCONTROL 设置为 ignoredups：<br/><br/><br/># pwd<br/># pwd<br/># pwd<br/># history &#124; tail -4<br/>44&nbsp;&nbsp;pwd<br/>45&nbsp;&nbsp;pwd<br/>46&nbsp;&nbsp;pwd [Note that there are three pwd commands in history, after executing pwd 3 times as shown above]<br/>47&nbsp;&nbsp;history &#124; tail -4<br/># export HISTCONTROL=ignoredups<br/># pwd<br/># pwd<br/># pwd<br/># history &#124; tail -3<br/>56&nbsp;&nbsp;export HISTCONTROL=ignoredups<br/>57&nbsp;&nbsp;pwd [Note that there is only one pwd command in the history, even after executing pwd 3 times as shown above]<br/>58&nbsp;&nbsp;history &#124; tail -4<br/><br/>使用 HISTCONTROL 清除整个命令历史中的重复条目<br/><br/>上例中的 ignoredups 只能剔除连续的重复条目。要清除整个命令历史中的重复条目，可以将 HISTCONTROL 设置成 erasedups：<br/><br/><br/># export HISTCONTROL=erasedups<br/># pwd<br/># service httpd stop<br/># history &#124; tail -3<br/>38&nbsp;&nbsp;pwd<br/>39&nbsp;&nbsp;service httpd stop<br/>40&nbsp;&nbsp;history &#124; tail -3<br/># ls -ltr<br/># service httpd stop<br/># history &#124; tail -6<br/>35&nbsp;&nbsp;export HISTCONTROL=erasedups<br/>36&nbsp;&nbsp;pwd<br/>37&nbsp;&nbsp;history &#124; tail -3<br/>38&nbsp;&nbsp;ls -ltr<br/>39&nbsp;&nbsp;service httpd stop<br/>[Note that the previous service httpd stop after pwd got erased]<br/>40&nbsp;&nbsp;history &#124; tail -6<br/><br/>使用 HISTCONTROL 强制 history 不记住特定的命令<br/><br/>将 HISTCONTROL 设置为 ignorespace，并在不想被记住的命令前面输入一个空格：<br/><br/><br/># export HISTCONTROL=ignorespace<br/># ls -ltr<br/># pwd<br/>#&nbsp;&nbsp;service httpd stop [Note that there is a space at the beginning of service, to ignore this command from history]<br/># history &#124; tail -3<br/>67&nbsp;&nbsp;ls -ltr<br/>68&nbsp;&nbsp;pwd<br/>69&nbsp;&nbsp;history &#124; tail -3<br/>使用 -c 选项清除所有的命令历史<br/><br/>如果你想清除所有的命令历史，可以执行：<br/><br/># history -c<br/>命令替换<br/><br/>在下面的例子里，!!:$ 将为当前的命令获得上一条命令的参数：<br/><br/><br/># ls anaconda-ks.cfg<br/>anaconda-ks.cfg<br/># vi !!:$<br/>vi anaconda-ks.cfg<br/><br/>补充：使用 !$ 可以达到同样的效果，而且更简单。[感谢 wanzigunzi 读者补充]<br/><br/>下例中，!^ 从上一条命令获得第一项参数：<br/><br/><br/># cp anaconda-ks.cfg anaconda-ks.cfg.bak<br/>anaconda-ks.cfg<br/># vi -5 !^<br/>vi anaconda-ks.cfg<br/><br/>为特定的命令替换指定的参数<br/><br/>在下面的例子，!cp:2 从命令历史中搜索以 cp 开头的命令，并获取它的第二项参数：<br/><br/><br/># cp ~/longname.txt /really/a/very/long/path/long-filename.txt<br/># ls -l !cp:2<br/>ls -l /really/a/very/long/path/long-filename.txt<br/><br/>下例里，!cp:$ 获取 cp 命令的最后一项参数：<br/><br/><br/># ls -l !cp:$<br/>ls -l /really/a/very/long/path/long-filename.txt<br/><br/>使用 HISTSIZE 禁用 history<br/><br/>如果你想禁用 history，可以将 HISTSIZE 设置为 0：<br/><br/><br/># export HISTSIZE=0<br/># history<br/># [Note that history did not display anything]<br/><br/>使用 HISTIGNORE 忽略历史中的特定命令<br/><br/>下面的例子，将忽略 pwd、ls、ls -ltr 等命令：<br/><br/><br/># export HISTIGNORE=”pwd:ls:ls -ltr:”<br/># pwd<br/># ls<br/># ls -ltr<br/># service httpd stop<br/># history &#124; tail -3<br/>79&nbsp;&nbsp;export HISTIGNORE=”pwd:ls:ls -ltr:”<br/>80&nbsp;&nbsp;service httpd stop<br/>81&nbsp;&nbsp;history<br/>[Note that history did not record pwd, ls and ls -ltr]<br/>来源：http://linuxtoy.org/archives/history-command-usage-examples.html
]]>
</description>
</item><item>
<link>http://jackxiang.com/post//#blogcomment</link>
<title><![CDATA[[评论] [实践OK]Linux 下History（历史）命令用法 15 例，linux下用ctrl+r快速搜索history及SecureCRT历史答疑。history能保存多少命令？限制同一ID不能两人同时登录能解决SecureCRT只用一个用户登录history的问题吗？不能这么干。]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://jackxiang.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>