标题: 【Linux 小技巧】How To Search Shell Command History (查看:415 回复:3)
石頭仔
版主

综合提问


现役斑竹  
UID 529794
精华 2
积分 244
帖子 1232
MST币 8077 点    
BST币 244 点    赚取
阅读权限 180
注册 2007-6-12
来自 【廣東★豬海】现在住在江苏 ...
状态 离线
 
[ 使用道具 ]  
发表于 2008-3-24 23:43  [ 资料 ]  [ 博客 ]  [ 主页 ] [ 短消息 ]  [ 加为好友添加 石頭仔 为MSN好友 通过MSN和 石頭仔 交谈 QQ Yahoo!
爱琴思邮件系统iGENUS V5.0
【Linux 小技巧】How To Search Shell Command History
本帖发表在我是网管论坛,帖子地址:http://bbs.54master.com/238622,1,1
Q. How do I search old command history under bash shell? How do I display or modify previous commands?


A. Almost all modern shell allows you to search command history if enabled by user. Use history command to display the history list with line numbers. Lines listed with with a * have been modified by user.


Shell history search commandType history at a shell prompt:

$ history


Output:
Sample output:
  
6  du -c   
7  du -ch   
8  ls [01-15]*-2008   
9  ls -ld [01-15]*-2008   
10  ls -ld [1-15]*-2008   
11  ls -ld [0]*-2008   
12  ls -ld [01]*-2008   
13  rm -vrf [01]*-2008   
14  du -ch   
15  ls   
16  cd   
17  umount /mnt   
18  df -H   
19  vnstat   
20  yum update   
21  vnstat -m   
22  vnstat -m -i eth0

....
...  

996  ping router.nixcraft.in  
997  ssh vivek@p1.vpn.nixcraft.in  
998  alias  
999  ~/scripts/clean.rss --fetch
1000  vnstat
1001  ~/scripts/clean.rss  --update



To search particular command, enter:

$ history | grep command-name

$ history | egrep -i 'scp|ssh|ftp'



Emacs Line-Edit Mode Command History Searching
To get previous command containing string, hit [CTRL]+[r] followed by search string:

(reverse-i-search):

To get previous command, hit [CTRL]+[p]. You can also use up arrow key.

CTRL-p

To get next command, hit [CTRL]+[n]. You can also use down arrow key.

CTRL-n



fc command

fc stands for either “find command” or “fix command.



For example list last 10 command, enter:

$ fc -l 10


To list commands 130 through 150, enter:

$ fc -l 130 150


To list all commands since the last command beginning with ssh, enter:

$ fc -l ssh


You can edit commands 1 through 5 using vi text editor, enter:

$ fc -e vi 1 5


Delete command historyThe -c option causes the history list to be cleared by deleting all of the entries:

$ history -c



[ 本帖最后由 石頭仔 于 2008-3-24 23:51 编辑 ]

[ 点这里复制网址,推荐给你QQ/MSN上的好友们! ]
本站声明:以上内容由网友 石頭仔 提供,与54master立场无关!
《我是网管》论坛
[ 顶部 ]
石頭仔
版主

综合提问


现役斑竹  
UID 529794
精华 2
积分 244
帖子 1232
MST币 8077 点    
BST币 244 点    赚取
阅读权限 180
注册 2007-6-12
来自 【廣東★豬海】现在住在江苏 ...
状态 离线
 
[ 使用道具 ]  
发表于 2008-3-24 23:52  [ 资料 ]  [ 博客 ]  [ 主页 ] [ 短消息 ]  [ 加为好友添加 石頭仔 为MSN好友 通过MSN和 石頭仔 交谈 QQ Yahoo!
呃..我觉得这个技巧还蛮不错的

本站声明:以上内容由网友 石頭仔 提供,与54master立场无关!
《我是网管》论坛
[ 顶部 ]
zhangxiuyun
实习版主



UID 479024
精华 0
积分 1112
帖子 1112
MST币 9609 点    
BST币 1112 点    赚取
阅读权限 180
注册 2007-1-3
来自 江西赣州
状态 离线
 
[ 使用道具 ]  
发表于 2008-3-25 18:53  [ 资料 ]  [ 博客 ]  [ 短消息 ]  [ 加为好友QQ
支持你,我感觉也很不错!

本站声明:以上内容由网友 zhangxiuyun 提供,与54master立场无关!
《我是网管》论坛
欢迎大家常来linux\unix版块坐坐!!!
[ 顶部 ]
石頭仔
版主

综合提问


现役斑竹  
UID 529794
精华 2
积分 244
帖子 1232
MST币 8077 点    
BST币 244 点    赚取
阅读权限 180
注册 2007-6-12
来自 【廣東★豬海】现在住在江苏 ...
状态 离线
 
[ 使用道具 ]  
发表于 2008-3-25 23:32  [ 资料 ]  [ 博客 ]  [ 主页 ] [ 短消息 ]  [ 加为好友添加 石頭仔 为MSN好友 通过MSN和 石頭仔 交谈 QQ Yahoo!
HOHO..Linux版感觉好冷清啊..

可能这里高手太多吧..
咱们这种菜贴人家都不屑一顾的

本站声明:以上内容由网友 石頭仔 提供,与54master立场无关!
《我是网管》论坛
[ 顶部 ]
  
 



当前时区 GMT+8, 现在时间是 2008-7-7 12:07

Powered by Discuz! 5.5.0  © 2001-2007 Comsenz Inc.
Processed in 0.052607 second(s), 12 queries , Gzip enabled

清除 Cookies - 关于我是网管 - 联系我是网管 - 广告服务 - 诚聘版主 - 无图版 - WAP -