[Linux](八) --shell bash学习----alias与history

linux里面我们可以把一些惯用的命令设置成alias(别名)方便我们的使用,还可以使用history来查看使用过的命令。

1.查看目前有哪些别名

直接输入alias,就可以查看了
[Linux](八) --shell bash学习----alias与history

2.设置一个命令,把rm设置成rm -i

[Linux](八) --shell bash学习----alias与history
可以看到删除文件时,执行的是rm -i,会提示我们是否进行接下来的操作。

3.取消别名设置:

输入unalias rm

[Linux](八) --shell bash学习----alias与history

4.history:查看使用过的命令

[Linux](八) --shell bash学习----alias与history
就会把我们使用过的命令都列出来。

若只想列出前面几个的话,可以输入history -number

例子:
[Linux](八) --shell bash学习----alias与history

5.介绍一下history常用参数:

number:数字,列出最近的n条命令。

  • -c:将目前shell中的所以history内容删除掉。
  • -w:将目前的history记忆内容写入histfiles中。
  • -r:读取histfiles内容到history记忆中

6.history比较使用的方法

  • !number:执行第几条命令
  • !command:搜索以字符串开头的命令。
  • !!:执行上一个命令。

例子:
[Linux](八) --shell bash学习----alias与history

可以看到!502执行的是alias的命令。

例子:
[Linux](八) --shell bash学习----alias与history

搜索al开头的history中的命令。