爆款云主机2核4G限时秒杀,88元/年起!
查看详情

活动

天翼云最新优惠活动,涵盖免费试用,产品折扣等,助您降本增效!
热门活动
  • 618智算钜惠季 爆款云主机2核4G限时秒杀,88元/年起!
  • 免费体验DeepSeek,上天翼云息壤 NEW 新老用户均可免费体验2500万Tokens,限时两周
  • 云上钜惠 HOT 爆款云主机全场特惠,更有万元锦鲤券等你来领!
  • 算力套餐 HOT 让算力触手可及
  • 天翼云脑AOne NEW 连接、保护、办公,All-in-One!
  • 中小企业应用上云专场 产品组合下单即享折上9折起,助力企业快速上云
  • 息壤高校钜惠活动 NEW 天翼云息壤杯高校AI大赛,数款产品享受线上订购超值特惠
  • 天翼云电脑专场 HOT 移动办公新选择,爆款4核8G畅享1年3.5折起,快来抢购!
  • 天翼云奖励推广计划 加入成为云推官,推荐新用户注册下单得现金奖励
免费活动
  • 免费试用中心 HOT 多款云产品免费试用,快来开启云上之旅
  • 天翼云用户体验官 NEW 您的洞察,重塑科技边界

智算服务

打造统一的产品能力,实现算网调度、训练推理、技术架构、资源管理一体化智算服务
智算云(DeepSeek专区)
科研助手
  • 算力商城
  • 应用商城
  • 开发机
  • 并行计算
算力互联调度平台
  • 应用市场
  • 算力市场
  • 算力调度推荐
一站式智算服务平台
  • 模型广场
  • 体验中心
  • 服务接入
智算一体机
  • 智算一体机
大模型
  • DeepSeek-R1-昇腾版(671B)
  • DeepSeek-R1-英伟达版(671B)
  • DeepSeek-V3-昇腾版(671B)
  • DeepSeek-R1-Distill-Llama-70B
  • DeepSeek-R1-Distill-Qwen-32B
  • Qwen2-72B-Instruct
  • StableDiffusion-V2.1
  • TeleChat-12B

应用商城

天翼云精选行业优秀合作伙伴及千余款商品,提供一站式云上应用服务
进入甄选商城进入云市场创新解决方案
办公协同
  • WPS云文档
  • 安全邮箱
  • EMM手机管家
  • 智能商业平台
财务管理
  • 工资条
  • 税务风控云
企业应用
  • 翼信息化运维服务
  • 翼视频云归档解决方案
工业能源
  • 智慧工厂_生产流程管理解决方案
  • 智慧工地
建站工具
  • SSL证书
  • 新域名服务
网络工具
  • 翼云加速
灾备迁移
  • 云管家2.0
  • 翼备份
资源管理
  • 全栈混合云敏捷版(软件)
  • 全栈混合云敏捷版(一体机)
行业应用
  • 翼电子教室
  • 翼智慧显示一体化解决方案

合作伙伴

天翼云携手合作伙伴,共创云上生态,合作共赢
天翼云生态合作中心
  • 天翼云生态合作中心
天翼云渠道合作伙伴
  • 天翼云代理渠道合作伙伴
天翼云服务合作伙伴
  • 天翼云集成商交付能力认证
天翼云应用合作伙伴
  • 天翼云云市场合作伙伴
  • 天翼云甄选商城合作伙伴
天翼云技术合作伙伴
  • 天翼云OpenAPI中心
  • 天翼云EasyCoding平台
天翼云培训认证
  • 天翼云学堂
  • 天翼云市场商学院
天翼云合作计划
  • 云汇计划
天翼云东升计划
  • 适配中心
  • 东升计划
  • 适配互认证

开发者

开发者相关功能入口汇聚
技术社区
  • 专栏文章
  • 互动问答
  • 技术视频
资源与工具
  • OpenAPI中心
开放能力
  • EasyCoding敏捷开发平台
培训与认证
  • 天翼云学堂
  • 天翼云认证
魔乐社区
  • 魔乐社区

支持与服务

为您提供全方位支持与服务,全流程技术保障,助您轻松上云,安全无忧
文档与工具
  • 文档中心
  • 新手上云
  • 自助服务
  • OpenAPI中心
定价
  • 价格计算器
  • 定价策略
基础服务
  • 售前咨询
  • 在线支持
  • 在线支持
  • 工单服务
  • 建议与反馈
  • 用户体验官
  • 服务保障
  • 客户公告
  • 会员中心
增值服务
  • 红心服务
  • 首保服务
  • 客户支持计划
  • 专家技术服务
  • 备案管家

了解天翼云

天翼云秉承央企使命,致力于成为数字经济主力军,投身科技强国伟大事业,为用户提供安全、普惠云服务
品牌介绍
  • 关于天翼云
  • 智算云
  • 天翼云4.0
  • 新闻资讯
  • 天翼云APP
基础设施
  • 全球基础设施
  • 信任中心
最佳实践
  • 精选案例
  • 超级探访
  • 云杂志
  • 分析师和白皮书
  • 天翼云·创新直播间
市场活动
  • 2025智能云生态大会
  • 2024智算云生态大会
  • 2023云生态大会
  • 2022云生态大会
  • 天翼云中国行
天翼云
  • 活动
  • 智算服务
  • 产品
  • 解决方案
  • 应用商城
  • 合作伙伴
  • 开发者
  • 支持与服务
  • 了解天翼云
      • 文档
      • 控制中心
      • 备案
      • 管理中心

      Linux shell编程学习笔记38:history命令

      首页 知识中心 软件开发 文章详情页

      Linux shell编程学习笔记38:history命令

      2024-10-17 08:21:30 阅读次数:28

      命令,编程

      0 前言

      使用DOS的朋友,都知道可以在命令行提示符中使用上下光标键来浏览最近执行过的命令,这是基于DOS提供的DosKey命令。

      而在Unix和Linux的shell中,我们同样可以使用上下光标键来浏览最近执行过的命令历史纪录(history),这是因为有history命令。

      bash可以保存的过去曾经执行过的命令。当某个用户登录到shell中,会读取该用户家目录中的~/.bash_history文件,并将历史命令列表保存到内存中。当用户退出当前shell时,会将内存中的历史命令列表覆盖至~/.bash_history文件。

       1  history命令的功能、格式和退出状态

      我们可以使用 help history命令查看 history命令的帮助信息。

      purpleEndurer @ bash ~ $help history
       history: history [-c] [-d offset] [n] or history -anrw [filename] or history -ps arg [arg...]
           Display or manipulate the history list.
           
           Display the history list with line numbers, prefixing each modified
           entry with a `*'.  An argument of N lists only the last N entries.
           
           Options:
             -c        clear the history list by deleting all of the entries
             -d offset delete the history entry at offset OFFSET.
           
             -a        append history lines from this session to the history file
             -n        read all history lines not already read from the history file
             -r        read the history file and append the contents to the history
               list
             -w        write the current history to the history file 
               and append them to the history list
           
             -p        perform history expansion on each ARG and display the result
               without storing it in the history list
             -s        append the ARGs to the history list as a single entry
           
           If FILENAME is given, it is used as the history file.  Otherwise,
           if $HISTFILE has a value, that is used, else ~/.bash_history.
           
           If the $HISTTIMEFORMAT variable is set and not null, its value is used
           as a format string for strftime(3) to print the time stamp associated
           with each displayed history entry.  No time stamps are printed otherwise.
           
           Exit Status:
           Returns success unless an invalid option is given or an error occurs.
       purpleEndurer @ bash ~ $

      Linux shell编程学习笔记38:history命令

      1.1 history命令的功能

      history命令是一个内部命令,可以显示或操纵命令历史列表。

      purpleEndurer @ bash ~ $type history
      history is a shell builtin
      purpleEndurer @ bash ~ $

      Linux shell编程学习笔记38:history命令

      1.2 history命令的格式

      history [-c] [-d 偏移量] [历史记录数]

      或

      history -anrw [文件名]

      或

      history -ps 参数 [参数...]

      选项

      功能

      备注

      -a

      将当前会话的命令行历史追加到历史文件~/.bash_history中

      append

      -c

      删除所有条目从而清空历史列表内容。

      clear

      -d 偏移量

       从指定位置删除历史列表内容。

      delete

      历史记录数

      显示指定数量的历史命令纪录,应为正整数

      number

      -n

      从历史文件中读取所有未被读取的行

      not

      -p 参数

      对每一个指定参数展开历史并显示结果而不存储到历史列表中

      perform

      -r

      读取历史文件并将内容追加到历史列表中

      read

      -s 命令

      以单条记录将 指定命令 追加到历史列表中。如果指定了 文件名,则它将被作为历史文件。否则如果 $HISTFILE 变量有值的话使用之,不然使用 ~/.bash_history 文件。如果 $HISTTIMEFORMAT 变量被设定并且不为空,它的值会被用于 strftime(3) 的格式字符串来打印与每一个显示的历史条目想关联的时间戳,否则不打印时间戳。

      single

      -w [文件]

      将当前历史写入到历史文件中,并追加到历史列表中

      write

      1.3退出状态

      返回成功,除非使用了无效的选项或者发生错误。

      2 命令应用实例

      2.1 history:显示命令历史列表

      prupleEndurer @ bash ~ $ history
          1  PS1="prupleEndurer @ bash \w $ "
          2  history
      prupleEndurer @ bash ~ $ 

       

      Linux shell编程学习笔记38:history命令

       2.2 history -a:将当前会话的命令行历史追加到历史文件~/.bash_history中

      prupleEndurer @ bash ~ $ cat ~/.bash_history
       PS1="prupleEndurer @ bash \w $ "
       history -2
       echo $?
       history
       history -r
       history
       history
       history -a
       prupleEndurer @ bash ~ $ history -a
       prupleEndurer @ bash ~ $ cat ~/.bash_history
       PS1="prupleEndurer @ bash \w $ "
       history -2
       echo $?
       history
       history -r
       history
       history
       history -a
       history -n
       ls ~/.bash_history
       cat ~/.bash_history
       cat ~/.bash_history -a
       cls
       clear
       cat ~/.bash_history -a
       cls
       clear
       cat ~/.bash_history
       history -a
       prupleEndurer @ bash ~ $

      我们先执行cat ~/.bash_history 命令查看文件~/.bash_history的内容

      然后执行history -a 命令将当前会话的命令行历史追加到历史文件~/.bash_history中

      接着再次执行cat ~/.bash_history 命令查看文件~/.bash_history的内容

      可以看到文件~/.bash_history中确实增加了下面这些命令行:

      history -n
      ls ~/.bash_history
      cat ~/.bash_history
      cat ~/.bash_history -a
      cls
      clear
      cat ~/.bash_history -a
      cls
      clear
      cat ~/.bash_history
      history -a

      2.3 history -c:删除所有条目从而清空历史列表

      prupleEndurer @ bash ~ $ history
          1  PS1="prupleEndurer @ bash \w $ "
          2  history 0
          3  echo $?
          4  history
      prupleEndurer @ bash ~ $ history -c
      prupleEndurer @ bash ~ $ history
          1  history
      prupleEndurer @ bash ~ $ 

      我们先执行history 命令查看当前命令历史列表,内容如下:

      1  PS1="prupleEndurer @ bash \w $ "
          2  history 0
          3  echo $?
          4  history

      然后执行history -c 命令将当前会话的命令行历史列表清空

      接着再次执行history 命令查看当前命令历史列表,这时历史列表只有我们这次所输入的的命令:

      1  history

      之前的命令历史列表都被清空了。

      2.4 history -d 偏移量:从指定位置删除历史列表内容

      prupleEndurer @ bash ~ $ history
           1  PS1="prupleEndurer @ bash \w $ "
           2  history
           3  history 0
           4  echo $?
           5  history 3
           6  history
       prupleEndurer @ bash ~ $ history -d 2
       prupleEndurer @ bash ~ $ history
           1  PS1="prupleEndurer @ bash \w $ "
           2  history 0
           3  echo $?
           4  history 3
           5  history
           6  history -d 2
           7  history
       prupleEndurer @ bash ~ $

      Linux shell编程学习笔记38:history命令

      我们先执行history 命令查看当前命令历史列表,内容如下:

      1  PS1="prupleEndurer @ bash \w $ "
          2  history
          3  history 0
          4  echo $?
          5  history 3
          6  history

      然后执行history -d 2 命令将第2行命令删除

      接着再次执行history 命令查看当前命令历史列表,内容如下:

      1  PS1="prupleEndurer @ bash \w $ "
          2  history 0
          3  echo $?
          4  history 3
          5  history
          6  history -d 2
          7  history

      可以看到命令历史列表中之前的第2条纪录:

      2  history

      被删除了。 

      如果我指定的偏移量是负数,例如-2,命令将出错,退出状态码为1:

      prupleEndurer @ bash ~ $ history -d -2
      bash: history: -2: history position out of range
      prupleEndurer @ bash ~ $ echo $?
      1
      prupleEndurer @ bash ~ $ 

      Linux shell编程学习笔记38:history命令

      2.5 history 正整数:显示指定数量的历史命令纪录

      prupleEndurer @ bash ~/Code $ history
           1  history
       prupleEndurer @ bash ~/Code $ history 1
           2  history 1
       prupleEndurer @ bash ~/Code $ history 0
       prupleEndurer @ bash ~/Code $ history 2
           3  history 0
           4  history 2
       prupleEndurer @ bash ~/Code $ history
           1  history
           2  history 1
           3  history 0
           4  history 2
           5  history
       prupleEndurer @ bash ~/Code $

      Linux shell编程学习笔记38:history命令

      如果我们指定的是负数,将提示出错,命令退出值为2。

      prupleEndurer @ bash ~ $ history -2
      bash: history: -2: invalid option
      history: usage: history [-c] [-d offset] [n] or history -anrw [filename] or history -ps arg [arg...]prupleEndurer @ bash ~ $ echo $?
      2

      Linux shell编程学习笔记38:history命令

      2.6 history -r:读取历史文件并将内容追加到历史列表中

      prupleEndurer @ bash ~ $ history
           1  PS1="prupleEndurer @ bash \w $ "
           2  cat ~/.bash_history
           3  set | grep  $HISTFILE
           4  cat /home/csdn/.bash_history
           5  history -w
           6  cat /home/csdn/.bash_history
           7  history -w c.log
           8  cat c.log
           9  history
       prupleEndurer @ bash ~ $ history -r
       prupleEndurer @ bash ~ $ history
           1  PS1="prupleEndurer @ bash \w $ "
           2  cat ~/.bash_history
           3  set | grep  $HISTFILE
           4  cat /home/csdn/.bash_history
           5  history -w
           6  cat /home/csdn/.bash_history
           7  history -w c.log
           8  cat c.log
           9  history
          10  history -r
          11  PS1="prupleEndurer @ bash \w $ "
          12  cat ~/.bash_history
          13  set | grep  $HISTFILE
          14  cat /home/csdn/.bash_history
          15  history -w
          16  history
       prupleEndurer @ bash ~ $ cat /home/csdn/.bash_history
       PS1="prupleEndurer @ bash \w $ "
       cat ~/.bash_history
       set | grep  $HISTFILE
       cat /home/csdn/.bash_history
       history -w
       prupleEndurer @ bash ~ $

      Linux shell编程学习笔记38:history命令

      我们先执行history 命令查看当前命令历史列表共有9条,内容如下:

      1  PS1="prupleEndurer @ bash \w $ "
          2  cat ~/.bash_history
          3  set | grep  $HISTFILE
          4  cat /home/csdn/.bash_history
          5  history -w
          6  cat /home/csdn/.bash_history
          7  history -w c.log
          8  cat c.log
          9  history

      然后执行history -r 命令读取历史文件并将内容追加到历史列表中

      接着再次执行history 命令查看当前命令历史列表,共有16条,内容如下:

      1  PS1="prupleEndurer @ bash \w $ "
          2  cat ~/.bash_history
          3  set | grep  $HISTFILE
          4  cat /home/csdn/.bash_history
          5  history -w
          6  cat /home/csdn/.bash_history
          7  history -w c.log
          8  cat c.log
          9  history
         10  history -r
         11  PS1="prupleEndurer @ bash \w $ "
         12  cat ~/.bash_history
         13  set | grep  $HISTFILE
         14  cat /home/csdn/.bash_history
         15  history -w
         16  history

      我们用命令 cat /home/csdn/.bash_history 查看历史文件的内容:

      PS1="prupleEndurer @ bash \w $ "
      cat ~/.bash_history
      set | grep  $HISTFILE
      cat /home/csdn/.bash_history
      history -w

      可以看到,当前命令历史列表中的第10条-15条记录是从历史文件添加进来的。

      2.7 history -s 命令 :将 指定命令 追加到历史列表

      prupleEndurer @ bash ~/Code $ history
           1  PS1="prupleEndurer @ bash \w $ "
           2  ls
           3  cd Code
           4  pwd
           5  history
           6  pwd
           7  pwd
           8  pwd
           9  set | grep hist
          10  set | grep HIST
          11  export | grep HIST
          12  export
          13  history
       prupleEndurer @ bash ~/Code $ history -s abcd
       prupleEndurer @ bash ~/Code $ history
           1  PS1="prupleEndurer @ bash \w $ "
           2  ls
           3  cd Code
           4  pwd
           5  history
           6  pwd
           7  pwd
           8  pwd
           9  set | grep hist
          10  set | grep HIST
          11  export | grep HIST
          12  export
          13  history
          14  abcd
          15  history
       prupleEndurer @ bash ~/Code $

      Linux shell编程学习笔记38:history命令

      在上面的实例中, 我们执行命令 history -s abcd 将  abcd 加入到命令历史列表中。

      2.8 history -w [文件]:将当前历史写入到历史文件中,并追加到历史列表中

      2.8.1  将当前历史写入到默认历史文件中

      系统默认历史文件说明符由环境变量 HISTFILE 指定。

      prupleEndurer @ bash ~ $ set | grep  $HISTFILE
       HISTFILE=/home/csdn/.bash_history
       _=/home/csdn/.bash_history
       prupleEndurer @ bash ~ $ cat /home/csdn/.bash_history
       cat: /home/csdn/.bash_history: No such file or directory
       prupleEndurer @ bash ~ $ history -w
       prupleEndurer @ bash ~ $ cat /home/csdn/.bash_history
       PS1="prupleEndurer @ bash \w $ "
       cat ~/.bash_history
       set | grep  $HISTFILE
       cat /home/csdn/.bash_history
       history -w
       prupleEndurer @ bash ~ $

      Linux shell编程学习笔记38:history命令

      我们先执行 set | grep  $HISTFILE 命令 查询环境变量 HISTFILE 的值为:/home/csdn/.bash_history。

      然后我们执行  cat /home/csdn/.bash_history 命令查看 /home/csdn/.bash_history 的内容,结果这个文件不存在。

      接着我们执行 history -w  命令将命令行历史记录 保存到 /home/csdn/.bash_history。

      最后我们再次执行 cat /home/csdn/.bash_history 命令查看 /home/csdn/.bash_history 的内容,这次文件不仅存在,而且文件内容就是我们之前输入的命令。

      2.8.2  将当前历史写入到指定文件中

      我们将 命令行历史记录 保存到 到当前目录下的文件 c.log中。

      prupleEndurer @ bash ~ $ history -w c.log
       prupleEndurer @ bash ~ $ cat c.log
       PS1="prupleEndurer @ bash \w $ "
       cat ~/.bash_history
       set | grep  $HISTFILE
       cat /home/csdn/.bash_history
       history -w
       cat /home/csdn/.bash_history
       history -w c.log
       prupleEndurer @ bash ~ $

      Linux shell编程学习笔记38:history命令

        

      首先,我们执行命令  history -w c.log   将 命令行历史记录 保存到 到当前目录下的文件 c.log中。

      然后,我们执行命令  cat c.log   查看文件 c.log 的内容。

      2.9 !:重复执行命令

      2.9.1 !! 或 !-1:重复执行上一条命令

      prupleEndurer @ bash ~/Code $ pwd
       /home/csdn/Code
       prupleEndurer @ bash ~/Code $ !!
       pwd
       /home/csdn/Code
       prupleEndurer @ bash ~/Code $ !-1
       pwd
       /home/csdn/Code
       prupleEndurer @ bash ~/Code $

       

      Linux shell编程学习笔记38:history命令

      我们执行命令!! 或 !-1 ,均会重复执行上一条命令pwd

      除了以上两种方法,还有两种方法 :

      • 使用方向键↑选中命令,按↑↓调整,并回车执行
      • 按Ctrl + p,调出命令,并回车执行

       2.9.2 !命令历史列表列号 :重复执行历史列表中指定行的命令

      prupleEndurer @ bash ~ $ ls
       Code
       prupleEndurer @ bash ~ $ ls Code
       prupleEndurer @ bash ~ $ cd Code
       prupleEndurer @ bash ~/Code $ ls
       prupleEndurer @ bash ~/Code $ history
           1  PS1="prupleEndurer @ bash \w $ "
           2  ls
           3  ls Code
           4  cd Code
           5  ls
           6  history
       prupleEndurer @ bash ~/Code $ !2
       ls
       prupleEndurer @ bash ~/Code $ ! 2
       bash: 2: command not found

      Linux shell编程学习笔记38:history命令

      在上面的实例中,命令 !2 会执行命令历史列表中的 第2条命令 ls

      由于 当前目录 下没有内容,所以ls命令没有显示。

      如果 我们输入的命令是 ! 2,就会报错。

      注意:

      • ! 与 命令历史列表列号 之间不能有空格。
      • 命令历史列表列号如果为正整数,则从头往下数;如果为负整数,则从下往上倒数,例如!-1执行的就是命令列表中最后一条命令

      如果我们指定的命令历史列表列号 不在 命令历史列表实际列数中,会怎么样呢?

      prupleEndurer @ bash ~/Code $ !0
       bash: !0: event not found
       prupleEndurer @ bash ~/Code $ echo $?
       0
       prupleEndurer @ bash ~/Code $ !100
       bash: !100: event not found
       prupleEndurer @ bash ~/Code $ echo $?
       0
       prupleEndurer @ bash ~/Code $

      Linux shell编程学习笔记38:history命令

      我们执行命令 !0 和 !100,系统都会提示:event not found

      而命令返回值均为0。

       2.9.3 !字符串 :重复执行历史列表中以指定字符串开头的命令

      prupleEndurer @ bash ~/Code $ history
           1  PS1="prupleEndurer @ bash \w $ "
           2  ls
           3  ls Code
           4  cd Code
           5  ls
           6  history
           7  ls
           8  ! 2
           9  cd Code
          10  ehco $?
          11  echo $?
          12  echo $?
          13  echo $?
          14  echo $?
          15  echo $?
          16  history
       prupleEndurer @ bash ~/Code $ !cd
       cd Code
       bash: cd: Code: No such file or directory
       prupleEndurer @ bash ~/Code $ ! cd
       prupleEndurer @ bash ~ $ !ls
       ls
       Code
       prupleEndurer @ bash ~ $ !ls Cod
       ls Cod
       ls: cannot access Cod: No such file or directory
       prupleEndurer @ bash ~ $ echo $?
       2
       prupleEndurer @ bash ~ $

      我们行执行命令 history 查看当前命令历史列表

      然后先后执行 了 !cd 、 ! cd 、!ls  、!ls Cod 命令。从执行情况看,要注意两点:

      1. ! 和 字符串 之间不能有空格
      2. 如果命令历史列表中不包括指定字符串的命令,系统会直接执行字符串,比如 !ls Cod

      2.10 其它使用技巧

      网上介绍的一些使用技巧,大家可以试试。

      2.10.1  重新执行或查看命令历史中的命令

      • !:0 将前一条命令去除参数再执行
      • Ctrl + n显示当前历史中的下一条命令,但不执行
      • Ctrl + j执行当前命令
      • !?string 重复前一个包含string字符串的命令
      • !string:p   仅打印命令历史,而不执行
      • !$:p 打印输出!$(上一条命令的最后一个参数)的内容
      • !*:p 打印输出!*(上一条命令的所有参数)的内容
      • ^string 删除上一条命令中的第一个string
      • ^string1^string2将上一条命令中的第一个string1替换为string2
      • !:gs/string1/srting2 将上一条命令中所有的string1都替换为string2

      2.10.2 使用(reverse-i-search)模式

      Crtl + r:在命令历史中搜索命令

      Crtl + g:从历史搜索模式退出

      2.10.3 使用命令历史记录中的参数

      •  重新调用前一个命令中最后一个参数

           有3种方法:

      1. !$
      2. Esc . (点击Esc键后松开,然后点击.键)
      3. Alt+. (按住Alt键的同时点击.键),在一些终端软件中屏蔽了Alt功能键,需要开启
      • command !^      利用上一个命令的第一个参数做cmd的参数
      • command !$      利用上一个命令的最后一个参数做cmd的参数
      • command !*      利用上一个命令的全部参数做cmd的参数
      • command !:n     利用上一个命令的第n个参数做cmd的参数
      • command !n:^    调用第n条命令的第一个参数
      • command !n:$    调用第n条命令的最后一个参数
      • command !n:m    调用第n条命令的第m个参数
      • command !n:*    调用第n条命令的所有参数
      • command !srting:^   从命令历史中搜索string开头的命令,并获取它的第一个参数
      • command !srting:$   从命令历史中搜索string开头的命令,并获取它的最后一个参数
      • command !srting:n   从命令历史中搜索string开头的命令,并获取它的第n个参数
      • command !srting:*   从命令历史中搜索string开头的命令,并获取它的所有参数

      三、与history命令相关的环境变量

      prupleEndurer @ bash ~/Code $ set | grep HIST
      HISTFILE=/home/csdn/.bash_history
      HISTFILESIZE=500
      HISTSIZE=500

      Linux shell编程学习笔记38:history命令

      • HISTFILE        :指定了默认命令历史文件说明符
      • HISTFILESIZE:指定默认命令历史文件中保存命令的记录总数,即命令历史文件中最多只有HISTFILESIZE行
      • HISTSIZE       :指定了 history 命令输出的记录数,即输出命令历史文件中的最后HISTSIZE行
      版权声明:本文内容来自第三方投稿或授权转载,原文地址:https://blog.51cto.com/endurer/9146766,作者:PurpleEndurer,版权归原作者所有。本网站转在其作品的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如因作品内容、版权等问题需要同本网站联系,请发邮件至ctyunbbs@chinatelecom.cn沟通。

      上一篇:python基础编程day03

      下一篇:当构造与析构的函数体为空,会发生什么?

      相关文章

      2025-05-16 09:15:10

      Linux系统基础-进程信号超详细讲解

      Linux系统基础-进程信号超详细讲解

      2025-05-16 09:15:10
      kill , 信号 , 命令 , 进程
      2025-05-14 10:33:25

      30天拿下Rust之网络编程

      在现代软件开发中,网络编程无处不在。无论是构建高性能的服务器、实时通信应用,还是实现复杂的分布式系统,对网络编程技术的掌握都至关重要。Rust语言以其卓越的安全性、高性能和优秀的并发模型,为网络编程提供了坚实的基础。

      2025-05-14 10:33:25
      Rust , TCP , 使用 , 客户端 , 异步 , 编程
      2025-05-14 10:02:48

      MongoDB常用管理命令(1)

      MongoDB常用管理命令(1)

      2025-05-14 10:02:48
      会话 , 命令 , 操作 , 节点
      2025-05-14 09:51:21

      Docker大学生看了都会系列(三、常用帮助、镜像、容器命令)

      Docker大学生看了都会系列(三、常用帮助、镜像、容器命令)

      2025-05-14 09:51:21
      container , docker , 命令 , 容器 , 查看 , 镜像
      2025-05-13 09:53:23

      java检测当前CPU负载状态

      在Java中,直接检测CPU负载状态并不像在操作系统命令行中那样简单,因为Java标准库并没有直接提供这样的功能。

      2025-05-13 09:53:23
      CPU , 使用 , 命令 , 示例 , 获取 , 负载
      2025-05-13 09:49:27

      编程语言逻辑

      编程语言逻辑

      2025-05-13 09:49:27
      分类 , 学习 , 编程 , 编程语言 , 语言 , 逻辑
      2025-05-13 09:49:19

      脚本交互_脚本外交互_read基础

      脚本交互_脚本外交互_read基础

      2025-05-13 09:49:19
      read , 命令 , 基础知识 , 实践 , 小结 , 用户 , 输入
      2025-05-07 09:08:23

      行为模式---命令模式

      命令模式是一种行为设计模式,它的核心思想就是将请求封装为一个对象,此对象包含与请求相关的所有信息。可以用不同的请求对客户进行参数化。命令模式通过将请求的发送者和接收者解耦,支持请求的排队、记录、撤销等操作。

      2025-05-07 09:08:23
      创建 , 命令 , 对象 , 模式
      2025-05-06 09:19:39

      【30天玩转python】网络编程基础

      网络编程是指编写能够在网络上进行通信的程序,通过网络进行数据的发送与接收。Python 提供了许多库和工具来进行网络编程,如 socket、urllib 和 requests。

      2025-05-06 09:19:39
      TCP , 地址 , 端口 , 编程 , 网络
      2025-04-22 09:40:08

      【Linux】ip命令详解

      【Linux】ip命令详解

      2025-04-22 09:40:08
      ip , IP , 命令 , 网络接口
      查看更多
      推荐标签

      作者介绍

      天翼云小翼
      天翼云用户

      文章

      33561

      阅读量

      5236173

      查看更多

      最新文章

      编程语言逻辑

      2025-05-13 09:49:27

      【30天玩转python】网络编程基础

      2025-05-06 09:19:39

      【Linux】ip命令详解

      2025-04-22 09:40:08

      【Linux】ifconfig命令详解

      2025-04-22 09:28:31

      linux常用命令-pip命令详解(超详细)

      2025-04-18 07:10:44

      shell编程-date命令详解(超详细)

      2025-04-18 07:10:44

      查看更多

      热门文章

      7、awk编程语言

      2023-03-31 06:14:11

      leetcode刷题三十八

      2023-03-21 10:30:17

      数据结构与算法之七 栈

      2022-11-17 12:37:20

      游戏编程之六 游戏编程的特点

      2024-09-25 10:13:46

      leetcode刷题四十一

      2023-03-21 10:30:17

      leetcode刷题三十九

      2023-03-21 10:30:17

      查看更多

      热门标签

      java Java python 编程开发 代码 开发语言 算法 线程 Python html 数组 C++ 元素 javascript c++
      查看更多

      相关产品

      弹性云主机

      随时自助获取、弹性伸缩的云服务器资源

      天翼云电脑(公众版)

      便捷、安全、高效的云电脑服务

      对象存储

      高品质、低成本的云上存储服务

      云硬盘

      为云上计算资源提供持久性块存储

      查看更多

      随机文章

      如何在Java中实现高效并发编程

      python中布尔类型

      火山中文编程(PC) -- 变量与常量

      如何在Java中处理多线程

      python编程基础day19

      【第二章:Python语言基础】2.4 保留字与标识符

      • 7*24小时售后
      • 无忧退款
      • 免费备案
      • 专家服务
      售前咨询热线
      400-810-9889转1
      关注天翼云
      • 旗舰店
      • 天翼云APP
      • 天翼云微信公众号
      服务与支持
      • 备案中心
      • 售前咨询
      • 智能客服
      • 自助服务
      • 工单管理
      • 客户公告
      • 涉诈举报
      账户管理
      • 管理中心
      • 订单管理
      • 余额管理
      • 发票管理
      • 充值汇款
      • 续费管理
      快速入口
      • 天翼云旗舰店
      • 文档中心
      • 最新活动
      • 免费试用
      • 信任中心
      • 天翼云学堂
      云网生态
      • 甄选商城
      • 渠道合作
      • 云市场合作
      了解天翼云
      • 关于天翼云
      • 天翼云APP
      • 服务案例
      • 新闻资讯
      • 联系我们
      热门产品
      • 云电脑
      • 弹性云主机
      • 云电脑政企版
      • 天翼云手机
      • 云数据库
      • 对象存储
      • 云硬盘
      • Web应用防火墙
      • 服务器安全卫士
      • CDN加速
      热门推荐
      • 云服务备份
      • 边缘安全加速平台
      • 全站加速
      • 安全加速
      • 云服务器
      • 云主机
      • 智能边缘云
      • 应用编排服务
      • 微服务引擎
      • 共享流量包
      更多推荐
      • web应用防火墙
      • 密钥管理
      • 等保咨询
      • 安全专区
      • 应用运维管理
      • 云日志服务
      • 文档数据库服务
      • 云搜索服务
      • 数据湖探索
      • 数据仓库服务
      友情链接
      • 中国电信集团
      • 189邮箱
      • 天翼企业云盘
      • 天翼云盘
      ©2025 天翼云科技有限公司版权所有 增值电信业务经营许可证A2.B1.B2-20090001
      公司地址:北京市东城区青龙胡同甲1号、3号2幢2层205-32室
      • 用户协议
      • 隐私政策
      • 个人信息保护
      • 法律声明
      备案 京公网安备11010802043424号 京ICP备 2021034386号