您的位置主页 > 系统管理

Linux命令行记忆及history命令的使用

Emacs and Vi history 编辑快捷键:
Emacs 模式:
CTRL-p 历史列表上一个.
CTRL-n 历史列表下一个.
CTRL-r 向上搜索历史列表 (incremental search).
CTRL-s 向下搜索历史列表 (incremental search).
Meta-p 向上搜索历史列表 non-incremental search.
Meta-n 向下搜索历史列表using non-incremental search.
Meta-< 移动到历史列表顶端.
Meta-> 移动到历史列表末尾.
Vi 模式:
k 历史列表上一个.
j 历史列表下一个.
/string or CTRL-r 向上搜索历史列表(正则表达式).
?string or CTRL-s 向下搜索历史列表(正则表达式).
n 重复上次搜索(同方向)n次
N 重复上次搜索(反方向)n次
G 移动到历史列表第N行 (for example, 15G).


History 扩展:
Event Designators:
! 开始历史命令代换.
!! 上一条命令.
!n 上n条命令.
!-n 当前命令行数-n.
!string 最近的以string开头的历史命令.
!?string? 最近的包含string的历史命令 (后一个 ? 可省).
^string1^string2^ 快速代换,重复上条命令,用string2替换string1.
!# 重复当前已经输入的命令行.

Word Designators (word designators follow the event designators, separated by a colon):
0 命令行第0个参数(恩,和c/shell 相似,通常是命令的名字,不知道 c/shell?那当我没说).
n 命令行第n个参数.
^ 命令行第一个参数 (第二个单词)
$ 命令行最后一个参数.
% 上次?string?搜索匹配的单词.
x-y x-y的参数 (-y等价于0-y).
* 所有参数(就是不包括命令的名字).
x* 与x-$相同.
x- x到倒数地二个参数
.
Modi ers (modi ers follow word designators, separated by a colon):
h 删除所有后面的路径,只留下前面的
t 删除所有前面的路径,只留下后面的
r 删除后缀.xxx, 留下文件名
e 删除文件名, 留下后缀
p 打印结果命令,但不执行(恩,测试功能)
q 防止代换参数被再次替换(Quotes the substituted words, escaping further substitutions.这是原文)
x Quotes the substituted words, breaking them into words at blanks and newlines.
s/old/new/ 字符串替换(正则表达式,又没听过?当我没说)
& 重复上次替换
g 在当前行的所有单词范围执行s或者&命令(正则.....,算了).

下面是例子
History expansion examples:
$ echo a b c d e (executes `echo ab c d e`)
a b c d e
$ echo !!:3-$ (executes `echo c d e`)
c d e
$ echo !-2:*:q (executes `echo 'a b c d e'`)
a b c d e
$ echo !-3:1:2:4:x (executes `echo 'a' 'b' 'd'`)
a b d
$ echo !-4:1-3:s/a/foo/:s/b/bar/:s/c/baz/
(executes `echo foo bar baz`)
foo bar baz
  • 上一篇:了解Linux的时钟
  • 下一篇:CentOS 网站地址