三三世界-百宝箱

文章 分类 标签
130 9 247

公告

暂无站点公告

Linux 下查看命令行历史history

三三 2021-11-13 1511 0条评论 操作系统Linux使用 使用教程Linuxhistory

首页 / 正文

简介

Linux中,bash输入的历史记录,会存在.bash_history(或者说root/bash_history)。
通过history查看。

可以看到,不仅可以输出正确的命令,还可以输入错误的(如abc),而且输出的是history之前所有的命令(including history),bash_history不是缓存文件,关机不会清除,文件会保存最近的N条命令,N=$HISTFILESIZE。

history和bash_histroy区别
history查看输入的命令,bash_history保存之前输入命令的文件(通常在用户目录下,如(home/user),通过cat .bash_history 或者vim / nano 查看。

但是history是实时的,会查看之前输入的所有命令,但是bash_history却只能查看到上次结束bash时之前的命令,就是说当前在bash输入的命令会在关闭terminal后存在bash_history中。

可以通过history -c删除bash历史, 但是.bash_history里仍会有历史记录

常用命令
history N 显示最近的N条命令,例如history 5
history -d N 删除第N条命令,这个N就是前面的编号,例如history -d 990
history -c 清空命令历史
history -a 将当前会话中的命令历史写入指定文件
echo $HISTFILE 使用此命令查看环境变量

root@33f:~# echo $HISTFILE 
/root/.bash_history

echo $HISTFILESIZE 查看最大保存数目
export HISTTIMEFORMAT=’%F %T ’ 让history可以有时间戳显示
更多命令自行百度。

评论(0)

当前没有评论,还不快来留下第一个脚印吧


Copyright 2021 三三世界-百宝箱. All Rights Reserved.

最新评论

  • 三三

    @Doug Shume it's ok for me , you can post here.

  • refugiaguenther

    Saved as a favorite, I like your website!

  • josefa

    If some one wishes to be updated with hottest technologies after that he must be visit this site and be up to date daily.

  • Penzu

    Heello would you mind sharing which blog platform you're using? I'm planning to start my own blog in the near future but I'm having a tough time making a decision between BlogEngine/Wordpress/B2evolution and Drupal. The reason I ask is because your layout seems different then moost blogs and I'm looking for something completely unique. P.S Apologies forr being off-topic butt I had to ask!

  • Yupoo Fendi

    Thanks to my father who shared with me regarding this webpage, this website is genuinely amazing.

  • Doug Shume

    Hi, I have an overflow of customers that I'd like to send to you but I want to make sure you can handle more leads, let me know if you'd like me to send you more info.

  • SuperWind

    zh.us.to 有效
    kms.03k.org 有效
    kms.chinancce.com
    kms.shuax.com 有效
    kms.dwhd.org 有效
    kms.luody.info 有效
    kms.digiboy.ir 有效
    kms.lotro.cc 有效
    www.zgbs.cc 有效
    cy2617.jios.org 有效

  • 三三

    @         权限问题,试试sudo 再加命令。

  •         

    你好提示Permission denied 怎么办啊

日历

2024年05月

   1234
567891011
12131415161718
19202122232425
262728293031 

文章目录

上一张 下一张