加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

linux – 从历史记录执行一系列命令

发布时间:2020-12-14 01:26:34 所属栏目:Linux 来源:网络整理
导读:我正在使用Ubuntu,我想重复我执行的一系列命令.我试过类似的东西 for i in $(seq 2006 2013); do !; done; 但失败了,因为shell试图执行命令’!2006′. man history 也没有向我透露如何重复一系列命令. 解决方法 如果您使用的是bash(或ksh),则内置的 fc 允
我正在使用Ubuntu,我想重复我执行的一系列命令.我试过类似的东西

for i in $(seq 2006 2013); do !; 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中的经典技术是使用别名别名r =’fc -e – ‘,但由于bash的行为,有必要稍微扭曲它的手臂并使用别名r =’fc -e:’代替.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读