Linux更改配置文件实现执行history的时候显示时间和用户

[19:40:44 mo@CentOS6\ [ ~]$history 
    1  echo "hello"
    2  history 

history 配置文件.bash_profile
将下面的句子写进去:

export HISTTIMEFORMAT="%F %T $(whoami)"

即可实现history命令显示时间和用户

[19:48:01 mo@CentOS6\ [ ~]$cat .bash_profile
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
	. ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH
[19:48:19 mo@CentOS6\ [ ~]$nano .bash_profile
[19:53:30 mo@CentOS6\ [ ~]$cat .bash_profile
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
	. ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH
export HISTTIMEFORMAT="%F %T $(whoami)"
[19:53:47 mo@CentOS6\ [ ~]$history 
    1  echo "hello"
    2  history 
    3  history -h
    4  whatis history
    5  history [builtins] 1
    6  man history
    7  man 1 history
    8  getent man history
    9  cat .bash_profile
   10  nano .bash_profile
   11  cat .bash_profile
   12  history 
[19:55:18 mo@CentOS6\ [ ~]$. .bash_profile
[19:56:01 mo@CentOS6\ [ ~]$history
    1  2020-12-30 19:40:44 moecho "hello"
    2  2020-12-30 19:40:49 mohistory 
    3  2020-12-30 19:46:32 mohistory -h
    4  2020-12-30 19:46:42 mowhatis history
    5  2020-12-30 19:47:12 mohistory [builtins] 1
    6  2020-12-30 19:47:19 moman history
    7  2020-12-30 19:47:32 moman 1 history
    8  2020-12-30 19:48:00 mogetent man history
    9  2020-12-30 19:48:19 mocat .bash_profile
   10  2020-12-30 19:52:29 monano .bash_profile
   11  2020-12-30 19:53:47 mocat .bash_profile
   12  2020-12-30 19:55:18 mohistory 
   13  2020-12-30 19:56:01 mo. .bash_profile
   14  2020-12-30 19:56:12 mohistory

注意配置文件修改后,并没有立即生效,需要使用命令 . 或者source +文件 让文件生效

posted @ 2021-01-26 00:05  不聪明的小子  阅读(111)  评论(0编辑  收藏  举报