linux - 执行一系列历史命令

标签 linux shell ubuntu history

我正在使用 Ubuntu,我想重复我执行过的一系列命令。我试过类似的东西

for i in $(seq 2006 2013); do \!$i; done;

但失败了,因为 shell 试图执行命令 '!2006'。

man history

也没有告诉我如何重复一系列命令。

最佳答案

如果您正在使用 bash(或 ksh),fc内置允许您以各种方式操纵历史记录。

fc -l                   # list recent history.
fc -l      2006 2013    # list commands 2006..2013
fc         2006 2013    # launch editor with commands 2006..2013; executes what you save
fc -e pico 2006 2013    # launches the editor pico on command 2006..2013
fc -e -    2006 2013    # Suppresses the 'edit' phase (but only executes the first listed command)
fc -e :    2006 2013    # Launches the ':' command (a shell built-in) as the editor

ksh 中的经典技术是使用别名 alias r='fc -e -',但是由于 bash 的行为>,有必要稍微用力扭动它的 ARM 并使用 alias r='fc -e :' 代替。

关于linux - 执行一系列历史命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24699369/

相关文章:

linux - 无法使用 mkdir 理解 perror 的消息

linux - 高级 Shell 脚本菜单

linux - 使用 find 命令但排除两个目录中的文件

linux - 连接多个启动板存储库

linux - 配置minikube时出现磁盘空间错误如何解决

ubuntu - 在 Ubuntu 14.10 中构建 RethinkDb 服务器会导致错误

python - 如何将Azure应用服务Python版本从3.9.7更改为3.9.12?

linux - 如何测试变量是否是 Bash 中的数字?

bash - bash getopts 函数是否会破坏命令行选项?

linux - 用户在 chroot 中不存在错误