linux history

Linux命令总结—history命令

(1)命令功能

history命令用于显示指定数目的指令命令,读取历史命令文件中的目录到历史命令缓冲区和将历史命令缓冲区中的目录写入历史命令文件。

说明:bash启动的时候会读取~/.bash_history文件并载入到内存中,这个变量就用于设置.bash_history文件,bash退出时也会把内存中的历史回写到.bash_history文件,即history中显示的命令只保存在当前历史命令缓冲区中,只有退出登陆后系统才会把缓冲区的内容写入到历史命令文件中,当然也可以使用下面的命令参数实现。

(2)命令语法

history(选项) (参数)

(3)选项说明

  • -c:清空当前历史命令;
  • -d <行号>:清除指定行号的历史输入命令;
  • -a:将历史命令缓冲区中的命令写入历史命令文件中;
  • -r:将历史命令文件中的命令读入当前历史命令缓冲区;
  • -w:将当前历史命令缓冲区命令写入历史命令文件中。

(4)参数说明

  • n:打印最近的n条历史命令。

(5)实例

实例1:显示历史命令—history 数字

[[email protected] ~]#history 10
  991 alias
  992 alias -p
  993 man cd
  994 unalias network
  995 type network
  996 alias network=‘cat /etc/sysconfig/network-scripts/ifcfg-eth0‘
  997 unalias network
  998 type network
  999 man history
 1000 history 10

实例2:清除指定行号历史输入命令—history -d 行号

[[email protected] ~]#history -d 1000
[[email protected] ~]#history 5
  997 unalias network
  998 type network
  999 man history
 1000 history -d 1000
 1001 history 5

可以看到实例1中的历史输入命令“1000  history 10”已被清除。

实例3:执行指定行号的历史输入命令--! 行号

[[email protected] ~]#history 5
  999 man history
 1000 history -d 1000
 1001 history 5
 1002 pwd
 1003 history 5
[[email protected] ~]#!1002
pwd
/root

实例4:运行上一个输入命令— !!

[[email protected] ~]# pwd
/root
[[email protected] ~]# !!
pwd
/root

实例5:将历史命令缓冲区中的命令写入历史命令文件中—history -a

[[email protected] ~]# tail -10 .bash_history
cat .bash_history 
more .bash_history
history -5
history 5
pwd
history 5
pwd
ls -a
sz .bash_history
init  6
[[email protected] ~]#history -a
[[email protected] ~]# tail -10 .bash_history
pwd
ls -a
sz .bash_history
init  6
history 3
history 10
sy -y .bash_history
sz -y .bash_history
tail -10.bash_history
history -a
时间: 2025-01-06 19:28:43

linux history的相关文章

linux history历史记录命令详解

一.什么是history在bash功能中,它能记忆使用过的命令,这个功能最大的好处就是可以查询曾经做过的举动!从而可以知道你的运行步骤,那么就可以追踪你曾下达过的命令,以作为除错的工具! 二.History的保存那么命令记录在哪里呢?在家目录内的 .bash_history 里! 不过,需要留意的是,~/.bash_history 记录的是前一次登陆以前所运行过的命令,而至于这一次登陆所运行的命令都被缓存在内存中,当你成功的注销系统后,该命令记忆才会记录到 .bash_history 当中! 查

Linux History安全问题【保存记录防止删除】+完善Linux/UNIX审计 将每个shell命令记入日志

2011-09-27 22:11:51|  分类: rhel5_033|举报|字号 订阅 Linux利用PROMPT_COMMAND实现审计功能 这个系统审计,记录什么用户,在什么时间,做了什么操作. 然后将查到的信息记录到一个文件里. 一. 配置 1. 在/etc/profile 文件的最后,添加如下2行代码: export HISTORY_FILE=/var/log/`date ‘+%Y%m’`.log export PROMPT_COMMAND=’{ date “+%Y-%m-%d %T

Linux history时间用户ip设置

在使用linux服务器的时候发生一些不知道谁操作的问题,google一下说history命令可以查看到历史记录,用过之后发现还是不够详细,再google,原来可以自己设置history的显示. 1.用vi编辑器打开/etc/profile 2.最后加两句代码 USER_IP=`who -u am i 2>/dev/null| awk '{print $NF}'|sed -e 's/[()]//g'` export HISTTIMEFORMAT="[%F %T][`whoami`][${US

Linux History&amp;man

(一).第一周作业 1).Linux常见发行版本以及区别 debian: ubuntu,mint slackware:SUSE Linux Enterprise Server (SLES) OpenSuse桌面 redhat: RHEL: RedHat Enterprise Linux每18个月发行一个新版本CentOS:兼容RHEL的格式中标麒麟:中标软件Fedora:每6个月发行一个新版本 ArchLinux:轻量简洁 Gentoo:极致性能,不提供传统意义的安装程序摘自CSDN:Linux

linux history简单笔记!

添加:rm -f $HOME/.bash_history history行为审计: [[email protected] ~]# history     33  node6 2016-09-06-13-13-22 root 192.168.1.243 ./history.sh     34  node6 2016-09-06-13-13-22 root 192.168.1.243 cat history.sh     35  node6 2016-09-06-13-13-22 root 192.

让linux history命令显示命令的执行时间、在哪个机器执行的这个命令

1.在/etc/profile的最后添加如下部分: USER_IP=`who -u am i 2>/dev/null| awk '{print $NF}'|sed -e 's/[()]//g'` export HISTTIMEFORMAT="[%F %T][`whoami`][${USER_IP}] " 2. source /etc/profile 3.随便执行一下什么命令, 4.执行history,看效果: 311  [2013-08-28 14:39:20][root][19

linux history命令优化

主要功能: 1, 可以记录哪个ip和时间(精确到秒)以及哪个用户,作了哪些命令 2,最大日志记录增加到4096条 把下面的代码直接粘贴到/etc/profile后面就可以了 #history modify export HISTTIMEFORMAT="[%Y.%m.%d %H:%M:%S-$USER_IP-$USER]" USER_IP=`who -u am i &>/dev/null| awk '{print $NF}'|sed -e 's/[()]//g'` if [

Linux history命令

echo $HISTSIZE    #显示命令历史缓存条目数量 history -c        #清除命令历史记录 history 其它使用技巧: ![字母]         #执行匹配该字母的最近使用的命令. !!             #执行上一条命令 !$             #引用上一个命令的最后一个参数 给history:操作历史记录 添加日期.执行的用户等信息: echo 'HISTTIMEFORMAT="%F  %T  `whoami` "' >> 

[Linux]history 显示命令执行的时间

显示历史命令之行时间 这里的环境是centos5.8 vim ~/.bashrc 或者 ~/.bash_profile 增加 export HISTTIMEFORMAT="%F %T " 一次会话的话先执行 export HISTTIMEFORMAT="%F %T " 然后使用history 命令就行了 # history 500|grep get_charge_by_month 1002 2014-09-02 10:17:34 history -500|grep